pread
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10
- 2_2_9
- 2_4_6
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
pread(p1, p2, p3 = v3)
public
Reads maxlen bytes from ios using the pread system call and returns them as a string without modifying the underlying descriptor offset. This is advantageous compared to combining IO#seek and IO#read in that it is atomic, allowing multiple threads/process to share the same IO object for reading the file at various locations. This bypasses any userspace buffering of the IO layer. If the optional outbuf argument is present, it must reference a String, which will receive the data. Raises SystemCallError on error, EOFError at end of file and NotImplementedError if platform does not implement the system call.
File.write("testfile", "This is line one\nThis is line two\n") File.open("testfile") do |f| p f.read # => "This is line one\nThis is line two\n" p f.pread(12, 0) # => "This is line" p f.pread(9, 8) # => "line one\n" end