mirror of https://github.com/perkeep/perkeep.git
Move CountingReader to new camli/misc library
This commit is contained in:
parent
54057fb914
commit
8bfcb6a5a3
1
build.pl
1
build.pl
|
@ -417,6 +417,7 @@ TARGET: lib/go/camli/jsonconfig
|
|||
TARGET: lib/go/camli/jsonsign
|
||||
TARGET: lib/go/camli/lru
|
||||
TARGET: lib/go/camli/magic
|
||||
TARGET: lib/go/camli/misc
|
||||
TARGET: lib/go/camli/misc/amazon/s3
|
||||
TARGET: lib/go/camli/misc/httprange
|
||||
TARGET: lib/go/camli/mysqlindexer
|
||||
|
|
|
@ -18,7 +18,6 @@ package client
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"camli/blobref"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
@ -29,6 +28,9 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"camli/blobref"
|
||||
"camli/misc"
|
||||
)
|
||||
|
||||
var _ = log.Printf
|
||||
|
@ -293,7 +295,7 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) {
|
|||
contentsSize := int64(0)
|
||||
req.Body = ioutil.NopCloser(io.MultiReader(
|
||||
strings.NewReader(multiPartHeader),
|
||||
countingReader{h.Contents, &contentsSize},
|
||||
misc.CountingReader{h.Contents, &contentsSize},
|
||||
strings.NewReader(multiPartFooter)))
|
||||
|
||||
if h.Size >= 0 {
|
||||
|
@ -380,13 +382,3 @@ func (c *Client) Upload(h *UploadHandle) (*PutResult, os.Error) {
|
|||
return nil, os.NewError("Server didn't receive blob.")
|
||||
}
|
||||
|
||||
type countingReader struct {
|
||||
r io.Reader
|
||||
n *int64
|
||||
}
|
||||
|
||||
func (cr countingReader) Read(p []byte) (n int, err os.Error) {
|
||||
n, err = cr.r.Read(p)
|
||||
*cr.n += int64(n)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright 2011 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package misc
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// CountingReader wraps a Reader, incrementing N by the number of
|
||||
// bytes read. No locking is performed.
|
||||
type CountingReader struct {
|
||||
Reader io.Reader
|
||||
N *int64
|
||||
}
|
||||
|
||||
func (cr CountingReader) Read(p []byte) (n int, err os.Error) {
|
||||
n, err = cr.Reader.Read(p)
|
||||
*cr.N += int64(n)
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue