mirror of https://github.com/perkeep/perkeep.git
Fix Fetch -> FetchStreaming conversion
As blob.fetcherToSeekerWrapper.Fetch erroneously asserts that FetchStreaming returns a ReadSeekCloser everytime, it had to be changed. Move MaxBlobSize from blobserver to constants (new package). Change-Id: I4b4f22c302cbec84d77d21454e0c9e8aebdf73e5
This commit is contained in:
parent
dde76aec90
commit
36643ff986
|
@ -27,6 +27,7 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"camlistore.org/pkg/constants"
|
||||
"camlistore.org/pkg/osutil"
|
||||
"camlistore.org/pkg/types"
|
||||
)
|
||||
|
@ -64,8 +65,26 @@ func (w *fetcherToSeekerWrapper) Fetch(r Ref) (file types.ReadSeekCloser, size i
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
file = rc.(types.ReadSeekCloser)
|
||||
return
|
||||
file, ok := rc.(types.ReadSeekCloser)
|
||||
if ok {
|
||||
return
|
||||
}
|
||||
// we must make it seekable
|
||||
var slurp bytes.Buffer
|
||||
n, err := io.CopyN(&slurp, rc, constants.MaxBlobSize+1)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, 0, err
|
||||
}
|
||||
if n > constants.MaxBlobSize {
|
||||
return nil, 0, fmt.Errorf("blob %v too big", r)
|
||||
}
|
||||
return struct {
|
||||
io.ReadSeeker
|
||||
io.Closer
|
||||
}{
|
||||
bytes.NewReader(slurp.Bytes()),
|
||||
ioutil.NopCloser(nil),
|
||||
}, n, err
|
||||
}
|
||||
|
||||
// StreamingFetcher is the minimal interface for retrieving a blob from storage.
|
||||
|
|
|
@ -24,15 +24,12 @@ import (
|
|||
"time"
|
||||
|
||||
"camlistore.org/pkg/blob"
|
||||
"camlistore.org/pkg/constants"
|
||||
"camlistore.org/pkg/context"
|
||||
)
|
||||
|
||||
// MaxBlobSize is the size of a single blob in Camlistore.
|
||||
//
|
||||
// TODO: formalize this in the specs. This value of 16 MB is less than
|
||||
// App Engine's 32 MB request limit, much more than Venti's limit, and
|
||||
// much more than the ~64 KB & 256 KB chunks that the FileWriter make
|
||||
const MaxBlobSize = 16 << 20
|
||||
const MaxBlobSize = constants.MaxBlobSize
|
||||
|
||||
var ErrCorruptBlob = errors.New("corrupt blob; digest doesn't match")
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Copyright 2014 the Camlistore authors.
|
||||
|
||||
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 constants contains Camlistore constants.
|
||||
//
|
||||
// This is a leaf package, without dependencies.
|
||||
package constants
|
||||
|
||||
// MaxBlobSize is the size of a single blob in Camlistore.
|
||||
//
|
||||
// TODO: formalize this in the specs. This value of 16 MB is less than
|
||||
// App Engine's 32 MB request limit, much more than Venti's limit, and
|
||||
// much more than the ~64 KB & 256 KB chunks that the FileWriter make
|
||||
const MaxBlobSize = 16 << 20
|
Loading…
Reference in New Issue