Commit 239567f0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 379cc163
......@@ -21,12 +21,9 @@
package client
import (
"bytes"
"compress/zlib"
"context"
"crypto/sha1"
"fmt"
"io"
"math/rand"
"net/url"
......@@ -104,29 +101,6 @@ func (c *Client) LastOid(ctx context.Context) (zodb.Oid, error) {
panic("TODO")
}
// decompress decompresses data according to zlib encoding.
//
// out buffer, if there is enough capacity, is used for decompression destination.
// if out has not not enough capacity a new buffer is allocated and used.
//
// return: destination buffer with full decompressed data or error.
func decompress(in []byte, out []byte) ([]byte, error) {
bin := bytes.NewReader(in)
zr, err := zlib.NewReader(bin)
if err != nil {
return nil, err
}
defer zr.Close()
bout := bytes.NewBuffer(out)
_, err = io.Copy(bout, bin)
if err != nil {
return nil, err
}
return bout.Bytes(), nil
}
func (c *Client) Load(ctx context.Context, xid zodb.Xid) (data []byte, serial zodb.Tid, err error) {
// XXX check pt is operational first? -> no if there is no data - we'll
// just won't find ready cell
......
package client
// misc utilities
import (
"bytes"
"compress/zlib"
"context"
"io"
......@@ -16,3 +19,26 @@ func lclose(ctx context.Context, c io.Closer) {
log.Error(ctx, err)
}
}
// decompress decompresses data according to zlib encoding.
//
// out buffer, if there is enough capacity, is used for decompression destination.
// if out has not not enough capacity a new buffer is allocated and used.
//
// return: destination buffer with full decompressed data or error.
func decompress(in []byte, out []byte) ([]byte, error) {
bin := bytes.NewReader(in)
zr, err := zlib.NewReader(bin)
if err != nil {
return nil, err
}
defer zr.Close()
bout := bytes.NewBuffer(out)
_, err = io.Copy(bout, bin)
if err != nil {
return nil, err
}
return bout.Bytes(), nil
}
......@@ -365,6 +365,10 @@ func (nl *NodeLink) Accept(ctx context.Context) (c *Conn, err error) {
}
return nil, ErrLinkDown
// XXX for long-lived links - better to propagate ctx cancel to link.Close to
// lower cases that are run at every select.
//
// XXX see xio.CloseWhenDone() for helper for this.
// XXX ctx cancel tests
case <-ctx.Done():
return nil, ctx.Err()
......
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