-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
able to get chunk Index from Index, fix writer #3
Conversation
chunk.go
Outdated
@@ -76,9 +76,17 @@ func (ch *Chunk) dump(w io.Writer, compressorIndex int) error { | |||
return nil | |||
} | |||
|
|||
type dummyCloser struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dummyCloser ==> noopCompressor ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
chunk.go
Outdated
func compressData(src io.Reader, compressorIndex int) (*bytes.Buffer, error) { | ||
compressed := new(bytes.Buffer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function should be somehow like the following:
func compressData(src io.Reader, compressorIndex int) (*bytes.Buffer, error) {
var compressed bytes.Buffer
var compressor io.WriteCloser
switch compressorIndex {
case NoCompression:
compressor = &noopCompressor{compressed}
case Snappy:
compressor = snappy.NewBufferedWriter(compressed)
case Gzip:
compressor = gzip.NewWriter(compressed)
default:
return nil, fmt.Errorf("Unknown compression algorithm: %d", compressorIndex)
}
defer compressor.Close()
if _, e := io.Copy(compressor, src); e != nil {
return nil, fmt.Errorf("Failed to compress chunk data: %v", e)
}
return &compressed, nil
}
The point is that compressed
is still of type bytes.Buffer
, and we just create a noopCompressor
which works like snappy.Writer
and gzip.Writer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better, thanks! Done.
header.go
Outdated
@@ -21,6 +19,11 @@ const ( | |||
Gzip | |||
) | |||
|
|||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we merge this const
group with the previous one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
reader.go
Outdated
@@ -19,11 +23,15 @@ func LoadIndex(r io.ReadSeeker) (*Index, error) { | |||
for { | |||
hdr, e = parseHeader(r) | |||
if e != nil { | |||
if e != io.EOF { | |||
fmt.Println("parse err:", e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this snippet for debugging? Should we remove it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done.
writer.go
Outdated
maxChunkSize = defaultMaxChunkSize | ||
} | ||
|
||
if compressor == -1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== -1
==> < 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
No description provided.