1
0
mirror of https://github.com/golang/go synced 2024-11-12 03:40:21 -07:00

doc: gofix io2010 demo programs

R=golang-dev, gri, r, agl
CC=golang-dev
https://golang.org/cl/4696046
This commit is contained in:
Andrew Gerrand 2011-07-13 09:40:49 +10:00
parent f340b3de5a
commit ba91dac3a9
2 changed files with 15 additions and 15 deletions

View File

@ -6,32 +6,32 @@ package main
import (
"crypto/aes"
"crypto/block"
"crypto/cipher"
"compress/gzip"
"io"
"os"
)
func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) {
r, _ := os.Open(srcfile, os.O_RDONLY, 0)
r, _ := os.Open(srcfile)
var w io.Writer
w, _ = os.Open(dstfile, os.O_WRONLY|os.O_CREATE, 0666)
w, _ = os.Create(dstfile)
c, _ := aes.NewCipher(key)
w = block.NewOFBWriter(c, iv, w)
w2, _ := gzip.NewDeflater(w)
w = cipher.StreamWriter{S: cipher.NewOFB(c, iv), W: w}
w2, _ := gzip.NewWriter(w)
io.Copy(w2, r)
w2.Close()
}
func DecryptAndGunzip(dstfile, srcfile string, key, iv []byte) {
f, _ := os.Open(srcfile, os.O_RDONLY, 0)
f, _ := os.Open(srcfile)
defer f.Close()
c, _ := aes.NewCipher(key)
r := block.NewOFBReader(c, iv, f)
r, _ = gzip.NewInflater(r)
w, _ := os.Open(dstfile, os.O_WRONLY|os.O_CREATE, 0666)
r := cipher.StreamReader{S: cipher.NewOFB(c, iv), R: f}
r2, _ := gzip.NewReader(r)
w, _ := os.Create(dstfile)
defer w.Close()
io.Copy(w, r)
io.Copy(w, r2)
}
func main() {

View File

@ -6,21 +6,21 @@ package main
import (
"crypto/aes"
"crypto/block"
"crypto/cipher"
"compress/gzip"
"io"
"os"
)
func EncryptAndGzip(dstfile, srcfile string, key, iv []byte) {
r, _ := os.Open(srcfile, os.O_RDONLY, 0)
r, _ := os.Open(srcfile)
var w io.WriteCloser
w, _ = os.Open(dstfile, os.O_WRONLY|os.O_CREATE, 0666)
w, _ = os.Create(dstfile)
defer w.Close()
w, _ = gzip.NewDeflater(w)
w, _ = gzip.NewWriter(w)
defer w.Close()
c, _ := aes.NewCipher(key)
io.Copy(block.NewCBCEncrypter(c, iv, w), r)
io.Copy(cipher.StreamWriter{S: cipher.NewOFB(c, iv), W: w}, r)
}
func main() {