Skip to content

Commit

Permalink
ocf: add encoder Flush
Browse files Browse the repository at this point in the history
  • Loading branch information
yields authored Aug 25, 2020
1 parent a06921f commit 05b56a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ocf/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ func ExampleNewEncoder() {
log.Fatal(err)
}

if err := enc.Close(); err != nil {
if err := enc.Flush(); err != nil {
log.Fatal(err)
}

if err := f.Sync(); err != nil {
log.Fatal(err)
}
}
9 changes: 7 additions & 2 deletions ocf/ocf.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ func (e *Encoder) Encode(v interface{}) error {
return e.writer.Error
}

// Close closes the encoder, flushing the writer.
func (e *Encoder) Close() error {
// Flush flushes the underlying writer.
func (e *Encoder) Flush() error {
if e.count == 0 {
return nil
}
Expand All @@ -272,6 +272,11 @@ func (e *Encoder) Close() error {
return e.writer.Error
}

// Close closes the encoder, flushing the writer.
func (e *Encoder) Close() error {
return e.Flush()
}

func (e *Encoder) writerBlock() error {
e.writer.WriteLong(int64(e.count))

Expand Down

0 comments on commit 05b56a2

Please sign in to comment.