Returns true if stat is a zero-length file; false otherwise.
File.stat("testfile").zero? #=> false
Returns true if stat is a socket, false if it isn’t or if the operating system doesn’t support this feature.
File.stat("testfile").socket? #=> false
Returns true if the file is a block device, false if it isn’t or if the operating system doesn’t support this feature.
File.stat("testfile").blockdev? #=> false File.stat("/dev/hda1").blockdev? #=> true
If the buffer is locked, meaning it is inside locked block execution. Locked buffer can’t be resized or freed, and another lock can’t be acquired on it.
Locking is not thread safe, but is a semantic used to ensure buffers don’t move while being used by a system call.
buffer.locked do buffer.write(io) # theoretical system call interface end
If the buffer is private, meaning modifications to the buffer will not be replicated to the underlying file mapping.
# Create a test file: File.write('test.txt', 'test') # Create a private mapping from the given file. Note that the file here # is opened in read-only mode, but it doesn't matter due to the private # mapping: buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::PRIVATE) # => #<IO::Buffer 0x00007fce63f11000+4 MAPPED PRIVATE> # Write to the buffer (invoking CoW of the underlying file buffer): buffer.set_string('b', 0) # => 1 # The file itself is not modified: File.read('test.txt') # => "test"
Allows to process a buffer in exclusive way, for concurrency-safety. While the block is performed, the buffer is considered locked, and no other code can enter the lock. Also, locked buffer can’t be changed with resize or free.
The following operations acquire a lock: resize, free.
Locking is not thread safe. It is designed as a safety net around non-blocking system calls. You can only share a buffer between threads with appropriate synchronisation techniques.
buffer = IO::Buffer.new(4) buffer.locked? #=> false Fiber.schedule do buffer.locked do buffer.write(io) # theoretical system call interface end end Fiber.schedule do # in `locked': Buffer already locked! (IO::Buffer::LockedError) buffer.locked do buffer.set_string("test", 0) end end
Read at least length bytes from the io starting at the specified from position, into the buffer starting at offset. If an error occurs, return -errno.
If length is not given or nil, it defaults to the size of the buffer minus the offset, i.e. the entire buffer.
If length is zero, exactly one pread operation will occur.
If offset is not given, it defaults to zero, i.e. the beginning of the buffer.
IO::Buffer.for('test') do |buffer| p buffer # => # <IO::Buffer 0x00007fca40087c38+4 SLICE> # 0x00000000 74 65 73 74 test # take 2 bytes from the beginning of urandom, # put them in buffer starting from position 2 buffer.pread(File.open('/dev/urandom', 'rb'), 0, 2, 2) p buffer # => # <IO::Buffer 0x00007f3bc65f2a58+4 EXTERNAL SLICE> # 0x00000000 05 35 73 74 te.5 end
A set of tasks to prepare the file in order to parse it
Sends a LOCK request to the server; returns an instance of a subclass of Net::HTTPResponse.
The request is based on the Net::HTTP::Lock object created from string path, string body, and initial headers hash initheader.
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.lock('/todos/1', data)
Sends an UNLOCK request to the server; returns an instance of a subclass of Net::HTTPResponse.
The request is based on the Net::HTTP::Unlock object created from string path, string body, and initial headers hash initheader.
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.unlock('/todos/1', data)
Inserts switch at the head of the list, and associates short, long and negated long options. Arguments are:
switchOptionParser::Switch instance to be inserted.
short_optsList of short style options.
long_optsList of long style options.
nolong_optsList of long style options with “no-” prefix.
prepend(switch, short_opts, long_opts, nolong_opts)
Opens a block for grouping objects to be pretty printed.
Arguments:
indent - noop argument. Present for compatibility.
open_obj - text appended before the &blok. Default is ”
close_obj - text appended after the &blok. Default is ”
open_width - noop argument. Present for compatibility.
close_width - noop argument. Present for compatibility.
def octal?: () -> bool
def frozen?: () -> bool
True if the parser encountered an error during parsing.