class Compress::XZ::Writer
- Compress::XZ::Writer
- IO
- Reference
- Object
Overview
A write-only IO
object to compress data in the xz 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 Gzip::Writer
instance.
Example: compress a file
require "xz"
File.write("file.txt", "abcd")
File.open("./file.txt", "r") do |input_file|
File.open("./file.xz", "w") do |output_file|
Compress::XZ::Writer.open(output_file) do |xz|
IO.copy(input_file, xz)
end
end
end
Defined in:
xz/writer.crConstructors
-
.new(output : IO, preset : Int32 = PRESET::DEFAULT_COMPRESSION, sync_close : Bool = false)
Creates an instance of XZ::Writer.
-
.new(filename : String, preset : Int32 = PRESET::DEFAULT_COMPRESSION)
Creates a new writer to the given filename.
Class Method Summary
-
.open(io : IO, preset : Int32 = PRESET::DEFAULT_COMPRESSION, sync_close : Bool = false, &)
Creates a new writer for the given io, yields it to the given block, and closes it at its end.
-
.open(io : IO, preset : Int32 = PRESET::DEFAULT_COMPRESSION, sync_close = false, &)
Creates a new writer to the given io, yields it to the given block, and closes it at the end.
-
.open(filename : String, preset : Int32 = PRESET::DEFAULT_COMPRESSION, &)
Creates a new writer to the given filename, yields it to the given block, and closes it at the end.
Instance Method Summary
-
#close
Closes this writer.
-
#closed? : Bool
Returns
true
if this IO is closed. -
#flush
See
IO#flush
. -
#read(slice : Bytes)
Always raises
IO::Error
because this is a write-onlyIO
. -
#sync_close=(sync_close : Bool)
If
#sync_close?
istrue
, closing this IO will close the underlying IO. -
#sync_close? : Bool
If
#sync_close?
istrue
, closing this IO will close the underlying IO. -
#write(slice : Bytes) : Nil
See
IO#write
.
Constructor Detail
Creates an instance of XZ::Writer. #close
must be invoked after all data
has written.
Creates a new writer to the given filename.
Class Method Detail
Creates a new writer for the given io, yields it to the given block, and closes it at its end.
Creates a new writer to the given io, yields it to the given block, and closes it at the end.
Creates a new writer to the given filename, yields it to the given block, and closes it at the end.
Instance Method Detail
If #sync_close?
is true
, closing this IO will close the underlying IO.