Closes the GzipFile
object. This method calls close method of the associated IO
object. Returns the associated IO
object.
Same as IO#closed?
Specify the modification time (mtime
) in the gzip header. Using an Integer
.
Setting the mtime in the gzip header does not effect the mtime of the file generated. Different utilities that expand the gzipped files may use the mtime header. For example the gunzip utility can use the ‘-N` flag which will set the resultant file’s mtime to the value in the header. By default many tools will set the mtime of the expanded file to the mtime of the gzipped file, not the mtime in the header.
If you do not set an mtime, the default value will be the time when compression started. Setting a value of 0 indicates no time stamp is available.
Opens a file specified by filename
for writing gzip compressed data, and returns a GzipWriter
object associated with that file. Further details of this method are found in Zlib::GzipWriter.new
and Zlib::GzipFile.wrap
.
Opens a file specified by filename
as a gzipped file, and returns a GzipReader
object associated with that file. Further details of this method are in Zlib::GzipReader.new
and ZLib::GzipFile.wrap.
Returns the rest of the data which had read for parsing gzip format, or nil
if the whole gzip file is not parsed yet.
See Zlib::GzipReader
documentation for a description.
Returns the last access time for this file as an object of class Time
.
File.stat("testfile").atime #=> Wed Dec 31 18:00:00 CST 1969
Returns the modification time of stat.
File.stat("testfile").mtime #=> Wed Apr 09 08:53:14 CDT 2003
Returns the change time for stat (that is, the time directory information about the file was changed, not the file itself).
Note that on Windows (NTFS), returns creation time (birth time).
File.stat("testfile").ctime #=> Wed Apr 09 08:53:14 CDT 2003
Returns the birth time for stat.
If the platform doesn’t have birthtime, raises NotImplementedError
.
File.write("testfile", "foo") sleep 10 File.write("testfile", "bar") sleep 10 File.chmod(0644, "testfile") sleep 10 File.read("testfile") File.stat("testfile").birthtime #=> 2014-02-24 11:19:17 +0900 File.stat("testfile").mtime #=> 2014-02-24 11:19:27 +0900 File.stat("testfile").ctime #=> 2014-02-24 11:19:37 +0900 File.stat("testfile").atime #=> 2014-02-24 11:19:47 +0900
Returns true
if stat is a zero-length file; false
otherwise.
File.stat("testfile").zero? #=> false
Returns true
if the file is a character device, false
if it isn’t or if the operating system doesn’t support this feature.
File.stat("/dev/tty").chardev? #=> true
Returns true
if stat has the set-user-id permission bit set, false
if it doesn’t or if the operating system doesn’t support this feature.
File.stat("/bin/su").setuid? #=> true
Returns true
if stat has the set-group-id permission bit set, false
if it doesn’t or if the operating system doesn’t support this feature.
File.stat("/usr/sbin/lpc").setgid? #=> true
Returns true
if stat has its sticky bit set, false
if it doesn’t or if the operating system doesn’t support this feature.
File.stat("testfile").sticky? #=> false
Transfers ownership of the underlying memory to a new buffer, causing the current buffer to become uninitialized.
buffer = IO::Buffer.new('test') other = buffer.transfer other # => # #<IO::Buffer 0x00007f136a15f7b0+4 SLICE> # 0x00000000 74 65 73 74 test buffer # => # #<IO::Buffer 0x0000000000000000+0 NULL> buffer.null? # => true
If the buffer has 0 size: it is created by ::new
with size 0, or with ::for
from an empty string. (Note that empty files can’t be mapped, so the buffer created with ::map
will never be empty.)
The buffer is external if it references the memory which is not allocated or mapped by the buffer itself.
A buffer created using ::for
has an external reference to the string’s memory.
External buffer can’t be resized.
If the buffer is internal, meaning it references memory allocated by the buffer itself.
An internal buffer is not associated with any external memory (e.g. string) or file mapping.
Internal buffers are created using ::new
and is the default when the requested size is less than the IO::Buffer::PAGE_SIZE
and it was not requested to be mapped on creation.
Internal buffers can be resized, and such an operation will typically invalidate all slices, but not always.
If the buffer is shared, meaning it references memory that can be shared with other processes (and thus might change without being modified locally).
# Create a test file: File.write('test.txt', 'test') # Create a shared mapping from the given file, the file must be opened in # read-write mode unless we also specify IO::Buffer::READONLY: buffer = IO::Buffer.map(File.open('test.txt', 'r+'), nil, 0) # => #<IO::Buffer 0x00007f1bffd5e000+4 EXTERNAL MAPPED SHARED> # Write to the buffer, which will modify the mapped file: buffer.set_string('b', 0) # => 1 # The file itself is modified: File.read('test.txt') # => "best"
If the buffer is read only, meaning the buffer cannot be modified using set_value
, set_string
or copy
and similar.
Frozen strings and read-only files create read-only buffers.
Fill buffer with value
, starting with offset
and going for length
bytes.
buffer = IO::Buffer.for('test').dup # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 74 65 73 74 test buffer.clear # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 00 00 00 00 .... buf.clear(1) # fill with 1 # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 01 01 01 .... buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 02 02 01 .... buffer.clear(2, 1) # fill with 2, starting from offset 1 # => # <IO::Buffer 0x00007fca40087c38+4 INTERNAL> # 0x00000000 01 02 02 02 ....
Efficiently copy from a source IO::Buffer
into the buffer, at offset
using memmove
. For copying String
instances, see set_string
.
buffer = IO::Buffer.new(32) # => # #<IO::Buffer 0x0000555f5ca22520+32 INTERNAL> # 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ * buffer.copy(IO::Buffer.for("test"), 8) # => 4 -- size of buffer copied buffer # => # #<IO::Buffer 0x0000555f5cf8fe40+32 INTERNAL> # 0x00000000 00 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00 ........test.... # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
copy
can be used to put buffer into strings associated with buffer:
string = "data: " # => "data: " buffer = IO::Buffer.for(string) do |buffer| buffer.copy(IO::Buffer.for("test"), 5) end # => 4 string # => "data:test"
Attempt to copy into a read-only buffer will fail:
File.write('test.txt', 'test') buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY) buffer.copy(IO::Buffer.for("test"), 8) # in `copy': Buffer is not writable! (IO::Buffer::AccessError)
See ::map
for details of creation of mutable file mappings, this will work:
buffer = IO::Buffer.map(File.open('test.txt', 'r+')) buffer.copy(IO::Buffer.for("boom"), 0) # => 4 File.read('test.txt') # => "boom"
Attempt to copy the buffer which will need place outside of buffer’s bounds will fail:
buffer = IO::Buffer.new(2) buffer.copy(IO::Buffer.for('test'), 0) # in `copy': Specified offset+length is bigger than the buffer size! (ArgumentError)
It is safe to copy between memory regions that overlaps each other. In such case, the data is copied as if the data was first copied from the source buffer to a temporary buffer, and then copied from the temporary buffer to the destination buffer.
buffer = IO::Buffer.new(10) buffer.set_string("0123456789") buffer.copy(buffer, 3, 7) # => 7 buffer # => # #<IO::Buffer 0x000056494f8ce440+10 INTERNAL> # 0x00000000 30 31 32 30 31 32 33 34 35 36 0120123456
Returns the instruction sequence as a String
in human readable form.
puts RubyVM::InstructionSequence.compile('1 + 2').disasm
Produces:
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== 0000 trace 1 ( 1) 0002 putobject 1 0004 putobject 2 0006 opt_plus <ic:1> 0008 leave