Class: Bzip2::Writer

Inherits:
Data
  • Object
show all
Defined in:
lib/bzip2/writer.rb,
ext/bzip2/bzip2.c

Overview

A Bzip2::Writer represents a stream which compresses data written to it. It can be constructed with another IO object (a File) which data can be written to. Otherwise, data is all stored internally as a string and can be retrieved via the Bzip2::Writer#flush method

It can both write to files:

writer = Bzip2::Writer.open('file')
writer << data
writer.close

Bzip2::Writer.open('file'){ |f| f << data }

writer = Bzip2::Writer.new File.open('file')

And output data as a string

writer = Bzip2::Writer.new
writer << data
writer.flush # => data compressed via bz2

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject

Class Method Details

.allocateObject

.openObject

Instance Method Details

#<<(data) ⇒ Object

Append some data to this buffer, returning the buffer so this method can be chained

writer = Bzip2::Writer.new
writer << 'asdf' << 1 << obj << 'a'
writer.flush

Parameters:

  • data (#to_s)

    anything responding to #to_s

See Also:

  • IO#<<


41
42
# File 'lib/bzip2/writer.rb', line 41

def << data
end

#closeObject

#close!Object

#closed?Boolean Also known as: closed

Returns:

  • (Boolean)

#flushObject Also known as: finish

Similar to Bzip2::Writer#puts except a newline is not appended after each object appended to this buffer

See Also:

  • IO#print


54
55
# File 'lib/bzip2/writer.rb', line 54

def print *objs
end

#printf(format, *ojbs) ⇒ Object

Prints data to this buffer with the specified format.

See Also:

  • Kernel#sprintf


60
61
# File 'lib/bzip2/writer.rb', line 60

def printf format, *ojbs
end

#putcObject

#puts(*objs) ⇒ Object

Adds a number of strings to this buffer. A newline is also inserted into the buffer after each object

See Also:

  • IO#puts


47
48
# File 'lib/bzip2/writer.rb', line 47

def puts *objs
end

#to_ioFile, String

Returns the io stream underlying this stream. If the strem was constructed with a file, that is returned. Otherwise, an empty string is returned.

Returns:

  • (File, String)

    similar to whatever the stream was constructed with

Raises:

  • (IOError)

    if the stream has been closed



76
77
78
79
80
81
# File 'ext/bzip2/bzip2.c', line 76

VALUE bz_to_io(VALUE obj) {
    struct bz_file *bzf;

    Get_BZ2(obj, bzf);
    return bzf->io;
}

#writeObject