X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/959c24478e2c3a596a81cca359fd784c897f46a2..d8f3785bb69288663f4cc46bf4d609c6770452d5:/journal.go?ds=sidebyside diff --git a/journal.go b/journal.go index 3fb8f64..745ae79 100644 --- a/journal.go +++ b/journal.go @@ -77,6 +77,21 @@ func (j *Journal) Write(day string, line []byte) (Position, error) { return place, nil } +func (j *Journal) closeWriter() error { + if j.file == nil { + return nil + } + + err := j.file.Close() + j.file = nil + j.day = 0 + if err != nil { + return fmt.Errorf("close day file: %w", err) + } + + return nil +} + // Read returns the line at place without its newline. func (j *Journal) Read(place Position) ([]byte, error) { reader, open := j.readers[place.day] @@ -156,21 +171,6 @@ func (j *Journal) Scan(ctx context.Context, place Position, add func([]byte, Pos return nil } -func (j *Journal) closeWriter() error { - if j.file == nil { - return nil - } - - err := j.file.Close() - j.file = nil - j.day = 0 - if err != nil { - return fmt.Errorf("close day file: %w", err) - } - - return nil -} - // journalDayNumber returns the day YYYY-MM-DD as the number YYYYMMDD. func journalDayNumber(day string) (uint32, error) { number, err := strconv.ParseUint(strings.ReplaceAll(day, "-", ""), 10, 32)