Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Ye <benye@amazon.com>
  • Loading branch information
yeya24 committed Jul 6, 2023
1 parent 6486b6c commit a10991b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/block/indexheader/binary_reader.go
Expand Up @@ -300,10 +300,14 @@ func newBinaryWriter(id ulid.ULID, cacheFilename string, buf []byte) (w *binaryW
return w, w.writer.Write(w.buf.Get())
}

type PosWriterWithBuffer interface {
PosWriter
Buffer() []byte
}

type PosWriter interface {
Pos() uint64
Write(bufs ...[]byte) error
Buffer() []byte
Flush() error
Sync() error
Close() error
Expand Down Expand Up @@ -404,11 +408,6 @@ func (fw *FileWriter) Write(bufs ...[]byte) error {
return nil
}

// Buffer is not used at all for FileWriter.
func (fw *FileWriter) Buffer() []byte {
return nil
}

func (fw *FileWriter) Flush() error {
return fw.fileWriter.Flush()
}
Expand Down Expand Up @@ -466,7 +465,11 @@ func (w *binaryWriter) Write(p []byte) (int, error) {
}

func (w *binaryWriter) Buffer() []byte {
return w.writer.Buffer()
pwb, ok := w.writer.(PosWriterWithBuffer)
if ok {
return pwb.Buffer()
}
return nil
}

func (w *binaryWriter) Close() error {
Expand Down

0 comments on commit a10991b

Please sign in to comment.