class Compress::Brotli::Writer

Overview

A write-only IO object to compress data in the Brotli format.

Instances of this class wrap another IO object. When you write to this instance, it compresses the data and writes it to the underlying IO.

NOTE unless created with a block, #close must be invoked after all data has been written to a Brotli::Writer instance.

Example: compress a file

require "brotli"

File.write("file.txt", "abcd")

File.open("./file.txt", "r") do |input_file|
  File.open("./file.br", "w") do |output_file|
    Compress::Brotli::Writer.open(output_file) do |br|
      IO.copy(input_file, br)
    end
  end
end

Defined in:

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(output : IO, options : Brotli::WriterOptions = Brotli::WriterOptions.default, sync_close : Bool = false) #

def self.new(filename : String, options : Brotli::WriterOptions = Brotli::WriterOptions.default) #

Creates a new writer to the given filename.


Class Method Detail

def self.open(io : IO, options : Brotli::WriterOptions = Brotli::WriterOptions.default, sync_close : Bool = false, &) #

Creates a new writer for the given io, yields it to the given block, and closes it at its end.


def self.open(io : IO, options : Brotli::WriterOptions = Brotli::WriterOptions.default, sync_close = false, &) #

Creates a new writer to the given io, yields it to the given block, and closes it at the end.


def self.open(filename : String, options : Brotli::WriterOptions = Brotli::WriterOptions.default, &) #

Creates a new writer to the given filename, yields it to the given block, and closes it at the end.


Instance Method Detail

def close #

Closes this writer. Must be invoked after all data has been written.


def closed? : Bool #

Returns true if this IO is closed.


def flush #

See IO#flush.


def read(slice : Bytes) #

Always raises IO::Error because this is a write-only IO.


def sync_close=(sync_close : Bool) #

If #sync_close? is true, closing this IO will close the underlying IO.


def sync_close? : Bool #

If #sync_close? is true, closing this IO will close the underlying IO.


def write(slice : Bytes) : Nil #

See IO#write.