Skip to content
instance method

IO::Buffer#pwrite

(untyped, untyped, untyped) -> untyped
pwrite(io, from, [length, [offset]]) → written length or -errno

Write at least length bytes from the buffer starting at offset, into the io starting at the specified from position. 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 pwrite operation will occur.

If offset is not given, it defaults to zero, i.e. the beginning of the buffer.

If the from position is beyond the end of the file, the gap will be filled with null (0 value) bytes.

Example
out = File.open('output.txt', File::RDWR) # open for read/write, no truncation
IO::Buffer.for('1234567').pwrite(out, 2, 3, 1)

This leads to 234 (3 bytes, starting from position 1) being written into output.txt, starting from file position 2.

See also #private? #read #pread #readonly? also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1