Skip to content
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

Merged
merged 2 commits into from
May 24, 2017
Merged

able to get chunk Index from Index, fix writer #3

merged 2 commits into from
May 24, 2017

Conversation

helinwang
Copy link
Contributor

No description provided.

chunk.go Outdated
@@ -76,9 +76,17 @@ func (ch *Chunk) dump(w io.Writer, compressorIndex int) error {
return nil
}

type dummyCloser struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dummyCloser ==> noopCompressor ?

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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 (
Copy link
Owner

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?

Copy link
Contributor Author

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)
Copy link
Owner

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?

Copy link
Contributor Author

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== -1 ==> < 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@wangkuiyi wangkuiyi merged commit 1065839 into wangkuiyi:master May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants