Zlib::GzipWriter
is a class for writing gzipped files. GzipWriter
should be used with an instance of IO
, or IO-like, object.
Following two example generate the same result.
Zlib::GzipWriter.open('hoge.gz') do |gz| gz.write 'jugemu jugemu gokou no surikire...' end File.open('hoge.gz', 'w') do |f| gz = Zlib::GzipWriter.new(f) gz.write 'jugemu jugemu gokou no surikire...' gz.close end
To make like gzip(1) does, run following:
orig = 'hoge.txt' Zlib::GzipWriter.open('hoge.gz') do |gz| gz.mtime = File.mtime(orig) gz.orig_name = orig gz.write IO.binread(orig) end
NOTE: Due to the limitation of Ruby’s finalizer, you must explicitly close GzipWriter
objects by Zlib::GzipWriter#close
etc. Otherwise, GzipWriter
will be not able to write the gzip footer and will generate a broken gzip file.
Zlib::GzipReader
is the class for reading a gzipped file. GzipReader
should be used as an IO
, or -IO-like, object.
Zlib::GzipReader.open('hoge.gz') {|gz| print gz.read } File.open('hoge.gz') do |f| gz = Zlib::GzipReader.new(f) print gz.read gz.close end
Method
Catalogue The following methods in Zlib::GzipReader
are just like their counterparts in IO
, but they raise Zlib::Error
or Zlib::GzipFile::Error
exception if an error was found in the gzip file.
Be careful of the footer of the gzip file. A gzip file has the checksum of pre-compressed data in its footer. GzipReader
checks all uncompressed data against that checksum at the following cases, and if it fails, raises Zlib::GzipFile::NoFooter
, Zlib::GzipFile::CRCError
, or Zlib::GzipFile::LengthError
exception.
When an reading request is received beyond the end of file (the end of compressed data). That is, when Zlib::GzipReader#read
, Zlib::GzipReader#gets
, or some other methods for reading returns nil.
When Zlib::GzipFile#close
method is called after the object reaches the end of file.
When Zlib::GzipReader#unused
method is called after the object reaches the end of file.
The rest of the methods are adequately described in their own documentation.
exception to wait for reading by EINPROGRESS. see IO.select
.
exception to wait for writing by EINPROGRESS. see IO.select
.
IO::Buffer
is a efficient zero-copy buffer for input/output. There are typical use cases:
Create an empty buffer with ::new
, fill it with buffer using copy
or set_value
, set_string
, get buffer with get_string
or write it directly to some file with write
.
Create a buffer mapped to some string with ::for
, then it could be used both for reading with get_string
or get_value
, and writing (writing will change the source string, too).
Create a buffer mapped to some file with ::map
, then it could be used for reading and writing the underlying file.
Create a string of a fixed size with ::string
, then read
into it, or modify it using set_value
.
Interaction with string and file memory is performed by efficient low-level C mechanisms like ‘memcpy`.
The class is meant to be an utility for implementing more high-level mechanisms like Fiber::Scheduler#io_read
and Fiber::Scheduler#io_write
and parsing binary protocols.
Empty buffer:
buffer = IO::Buffer.new(8) # create empty 8-byte buffer # => # #<IO::Buffer 0x0000555f5d1a5c50+8 INTERNAL> # ... buffer # => # <IO::Buffer 0x0000555f5d156ab0+8 INTERNAL> # 0x00000000 00 00 00 00 00 00 00 00 buffer.set_string('test', 2) # put there bytes of the "test" string, starting from offset 2 # => 4 buffer.get_string # get the result # => "\x00\x00test\x00\x00"
Buffer from string:
string = 'buffer' buffer = IO::Buffer.for(string) # => # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE> # ... buffer # => # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE> # 0x00000000 64 61 74 61 buffer buffer.get_string(2) # read content starting from offset 2 # => "ta" buffer.set_string('---', 1) # write content, starting from offset 1 # => 3 buffer # => # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE> # 0x00000000 64 2d 2d 2d d--- string # original string changed, too # => "d---"
Buffer from file:
File.write('test.txt', 'test buffer') # => 9 buffer = IO::Buffer.map(File.open('test.txt')) # => # #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE> # ... buffer.get_string(5, 2) # read 2 bytes, starting from offset 5 # => "da" buffer.set_string('---', 1) # attempt to write # in `set_string': Buffer is not writable! (IO::Buffer::AccessError) # To create writable file-mapped buffer # Open file for read-write, pass size, offset, and flags=0 buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 9, 0, 0) buffer.set_string('---', 1) # => 3 -- bytes written File.read('test.txt') # => "t--- buffer"
The class is experimental and the interface is subject to change, this is especially true of file mappings which may be removed entirely in the future.
The error thrown when the parser encounters illegal CSV
formatting.
The error thrown when the parser encounters invalid encoding in CSV
.
Note: Don’t use this class directly. This is an internal class.
The DidYouMean::Formatter
is the basic, default formatter for the gem. The formatter responds to the message_for
method and it returns a human readable string.
The DidYouMean::Formatter
is the basic, default formatter for the gem. The formatter responds to the message_for
method and it returns a human readable string.
spell checker for a dictionary that has a tree structure, see doc/tree_spell_checker_api.md
Superclass of all errors raised in the DRb
module.
Class
responsible for converting between an object and its id.
This, the default implementation, uses an object’s local ObjectSpace
__id__ as its id. This means that an object’s identification over drb remains valid only while that object instance remains alive within the server runtime.
For alternative mechanisms, see DRb::TimerIdConv
in drb/timeridconv.rb and DRbNameIdConv in sample/name.rb in the full drb distribution.
An exception wrapping a DRb::DRbUnknown
object
An exception wrapping an error object
An Array
wrapper that can be sent to another server via DRb
.
All entries in the array will be dumped or be references that point to the local server.
Class
handling the connection between a DRbObject
and the server the real object lives on.
This class maintains a pool of connections, to reduce the overhead of starting and closing down connections for each method call.
This class is used internally by DRbObject
. The user does not normally need to deal with it directly.
Class
responsible for converting between an object and its id.
This, the default implementation, uses an object’s local ObjectSpace
__id__ as its id. This means that an object’s identification over drb remains valid only while that object instance remains alive within the server runtime.
For alternative mechanisms, see DRb::TimerIdConv
in drb/timeridconv.rb and DRbNameIdConv in sample/name.rb in the full drb distribution.
Gateway id conversion forms a gateway between different DRb
protocols or networks.
The gateway needs to install this id conversion and create servers for each of the protocols or networks it will be a gateway between. It then needs to create a server that attaches to each of these networks. For example:
require 'drb/drb' require 'drb/unix' require 'drb/gw' DRb.install_id_conv DRb::GWIdConv.new gw = DRb::GW.new s1 = DRb::DRbServer.new 'drbunix:/path/to/gateway', gw s2 = DRb::DRbServer.new 'druby://example:10000', gw s1.thread.join s2.thread.join
Each client must register services with the gateway, for example:
DRb.start_service 'drbunix:', nil # an anonymous server gw = DRbObject.new nil, 'drbunix:/path/to/gateway' gw[:unix] = some_service DRb.thread.join