Commit ac801304 authored by Kirill Smelkov's avatar Kirill Smelkov

X found thinko in decompress()

parent 5ef342b1
...@@ -26,16 +26,22 @@ func lclose(ctx context.Context, c io.Closer) { ...@@ -26,16 +26,22 @@ func lclose(ctx context.Context, c io.Closer) {
// if out has not not enough capacity a new buffer is allocated and used. // if out has not not enough capacity a new buffer is allocated and used.
// //
// return: destination buffer with full decompressed data or error. // return: destination buffer with full decompressed data or error.
func decompress(in []byte, out []byte) ([]byte, error) { func decompress(in []byte, out []byte) (data []byte, err error) {
bin := bytes.NewReader(in) bin := bytes.NewReader(in)
zr, err := zlib.NewReader(bin) zr, err := zlib.NewReader(bin)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer zr.Close() defer func() {
err2 := zr.Close()
if err2 != nil && err == nil {
err = err2
data = nil
}
}()
bout := bytes.NewBuffer(out) bout := bytes.NewBuffer(out)
_, err = io.Copy(bout, bin) _, err = io.Copy(bout, zr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
package client
import (
"testing"
"github.com/kylelemons/godebug/pretty"
)
var ztestv = []struct{in, out string}{
{
in: "x\x9c\xf3H\xcd\xc9\xc9W\x08\xcf/\xcaIQ\x04\x00\x1cI\x04>",
out: "Hello World!",
},
{
in: "x\x9cK.H-*\xce,.I\xcd+\xd1\xcbM,(\xc8\xccK\xe7\n\x80\x0b\xf9BE\n\x19\xf5j\x0b\x99BYR\x12K\x12\x0b\x99k\x0bYB\xd9\x8b3\xd3\xf3\x12s\xca\nY5B9\x18 \x80\xb1\x90-\xb9<5/%5'3O/)3=\xb1\xa8(\xb1R\x0fL\xc6W\xe5\xa7$qE9e\xa6;\x82\xb8\\\x85\xec%\x81\xc5\xc5z\x00\xb0d)\xef",
out: "cpersistent.mapping\nPersistentMapping\nq\x01.}q\x02U\x04dataq\x03}q\x04U\x07signalvq\x05(U\x08\x00\x00\x00\x00\x00\x00\x00\x01q\x06cwendelin.bigarray.array_zodb\nZBigArray\nq\x07tQss.",
},
}
func TestDecompress(t *testing.T) {
for _, tt := range ztestv {
got, err := decompress([]byte(tt.in), nil)
if err != nil {
t.Errorf("decompress err: %q", tt.in)
continue
}
gots := string(got)
if gots != tt.out {
t.Errorf("decompress output mismatch:\n%s\n",
pretty.Compare(tt.out, gots))
}
}
}
...@@ -208,7 +208,7 @@ gensqlite() { ...@@ -208,7 +208,7 @@ gensqlite() {
#neopylite #neopylite
neopysql neopysql
#time demo-zbigarray read neo://$cluster@$Mbind #time demo-zbigarray read neo://$cluster@$Mbind
#./zsha1.py neo://$cluster@$Mbind 2>py.log ./zsha1.py neo://$cluster@$Mbind 2>py.log
go run zsha1.go neo://$cluster@$Mbind 2>go.log go run zsha1.go neo://$cluster@$Mbind 2>go.log
xneoctl set cluster stopping xneoctl set cluster stopping
xmysql -e "SHUTDOWN" xmysql -e "SHUTDOWN"
......
...@@ -59,13 +59,16 @@ loop: ...@@ -59,13 +59,16 @@ loop:
m.Write(data) m.Write(data)
fmt.Fprintf(os.Stderr, "%d @%s\tsha1: %x\n", uint(oid), serial, m.Sum(nil)) fmt.Fprintf(os.Stderr, "%d @%s\tsha1: %x\n", uint(oid), serial, m.Sum(nil))
fmt.Fprintf(os.Stderr, "\tdata: %x\n", data)
nread += len(data) nread += len(data)
oid += 1 oid += 1
break
} }
tend := time.Now() tend := time.Now()
fmt.Printf("%x ; oid=0..%d nread=%d t=%s\n", fmt.Printf("%x ; oid=0..%d nread=%d t=%s x=zsha1.go\n",
m.Sum(nil), oid-1, nread, tend.Sub(tstart)) m.Sum(nil), oid-1, nread, tend.Sub(tstart))
} }
...@@ -32,13 +32,16 @@ def main(): ...@@ -32,13 +32,16 @@ def main():
m.update(data) m.update(data)
print('%s @%s\tsha1: %s' % (oid, u64(serial), m.hexdigest()), file=sys.stderr) print('%s @%s\tsha1: %s' % (oid, u64(serial), m.hexdigest()), file=sys.stderr)
print('\tdata: %s' % (data.encode('hex'),), file=sys.stderr)
nread += len(data) nread += len(data)
oid += 1 oid += 1
break
tend = time() tend = time()
print('%s ; oid=0..%d nread=%d t=%.3fs' % \ print('%s ; oid=0..%d nread=%d t=%.3fs x=zsha1.py' % \
(m.hexdigest(), oid-1, nread, tend - tstart)) (m.hexdigest(), oid-1, nread, tend - tstart))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment