class C0::Stream::Writer

Overview

Appends ETB-committed blocks to an append-only log.

C0::Stream::Writer.open("claims.c0") do |log| log.record("create", nonce, ts) log.batch do |b| b.record("name", label, ts) b.record("tag", tags, ts) end end

Each block and its ETB are issued as a single write. .open repairs a torn tail (truncates to the last commit) before appending.

Defined in:

c0/stream.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(io : IO, sync : Bool = false) #

[View source]
def self.open(path : Path | String, sync : Bool = true) : Writer #

Open a log file for appending, repairing any torn tail first.


[View source]

Class Method Detail

def self.open(path : Path | String, sync : Bool = true, & : Writer -> ) : Nil #

[View source]
def self.repair(path : Path | String) : Nil #

Truncate an uncommitted tail so the log ends at a commit marker.


[View source]

Instance Method Detail

def batch(& : Builder -> ) : Nil #

Append several records under a single commit. The batch is atomic: a tear anywhere inside it discards the whole block.


[View source]
def close : Nil #

[View source]
def flush : Nil #

[View source]
def group(name : String, headers : Indexable(String) | Nil = nil) : Nil #

Append a group preamble (GS + name) as a committed block.


[View source]
def header(names : Indexable(String)) : Nil #

Append an SOH header as a committed block.


[View source]
def header(*names : String) : Nil #

Append an SOH header as a committed block.


[View source]
def record(fields : Indexable(String)) : Nil #

Append one record as a committed block.


[View source]
def record(*fields : String) : Nil #

Append one record as a committed block.


[View source]
def sync : Bool #

When true and the underlying IO is a File, fsync after each commit.


[View source]
def sync=(sync : Bool) #

When true and the underlying IO is a File, fsync after each commit.


[View source]