ndjson

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ndjson provides NDJSON (newline-delimited JSON) format support for omnistorage.

Index

Constants

View Source
const (
	// DefaultBufferSize is the default buffer size for writers.
	DefaultBufferSize = 64 * 1024 // 64KB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements omnistorage.RecordReader for NDJSON format. Each record is read as a single line (delimited by newlines).

func NewReader

func NewReader(r io.ReadCloser) *Reader

NewReader creates a new NDJSON reader that reads from the given io.ReadCloser. The reader will be closed when the NDJSON reader is closed.

func NewReaderSize

func NewReaderSize(r io.ReadCloser, bufferSize int) *Reader

NewReaderSize creates a new NDJSON reader with the specified buffer size. The buffer size determines the maximum line length that can be read.

func (*Reader) Close

func (r *Reader) Close() error

Close releases any resources held by the reader.

func (*Reader) Read

func (r *Reader) Read() ([]byte, error)

Read reads the next record (JSON line) from the reader. Returns io.EOF when no more records are available. Empty lines are skipped. The returned slice is a copy and is valid until the next call to Read.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements omnistorage.RecordWriter for NDJSON format. Each record is written as a single line followed by a newline character.

func NewWriter

func NewWriter(w io.WriteCloser) *Writer

NewWriter creates a new NDJSON writer that writes to the given io.WriteCloser. The writer will be closed when the NDJSON writer is closed.

func NewWriterSize

func NewWriterSize(w io.WriteCloser, bufferSize int) *Writer

NewWriterSize creates a new NDJSON writer with the specified buffer size.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes any remaining data and closes the writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes any buffered data to the underlying writer.

func (*Writer) Write

func (w *Writer) Write(data []byte) error

Write writes a single record (JSON line) to the writer. The record should not contain embedded newlines; if it does, they will be preserved but may cause issues when reading.

func (*Writer) WriteJSON

func (w *Writer) WriteJSON(data []byte) error

WriteJSON writes a single record, trimming any trailing whitespace/newlines before adding the standard newline delimiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL