D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Buffer
/
Filename :
map-c.ri
back
Copy
U:RDoc::AnyMethod[iI"map:ETI"IO::Buffer::map;TT:publico:RDoc::Markup::Document:@parts[ o:RDoc::Markup::Paragraph; [I"NCreate an IO::Buffer for reading from +file+ by memory-mapping the file. ;TI"?+file_io+ should be a +File+ instance, opened for reading.;To:RDoc::Markup::BlankLine o; ; [I">Optional +size+ and +offset+ of mapping can be specified.;T@o; ; [I"QBy default, the buffer would be immutable (read only); to create a writable ;TI"Nmapping, you need to open a file in read-write mode, and explicitly pass ;TI"4+flags+ argument without IO::Buffer::IMMUTABLE.;T@o:RDoc::Markup::Verbatim; [I"$File.write('test.txt', 'test') ;TI" ;TI"Rbuffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY) ;TI"=# => #<IO::Buffer 0x00000001014a0000+4 MAPPED READONLY> ;TI" ;TI""buffer.readonly? # => true ;TI" ;TI"buffer.get_string ;TI"# => "test" ;TI" ;TI"buffer.set_string('b', 0) ;TI"G# `set_string': Buffer is not writable! (IO::Buffer::AccessError) ;TI" ;TI"D# create read/write mapping: length 4 bytes, offset 0, flags 0 ;TI"@buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 4, 0) ;TI"buffer.set_string('b', 0) ;TI"# => 1 ;TI" ;TI"# Check it ;TI"File.read('test.txt') ;TI"# => "best" ;T:@format0o; ; [I"RNote that some operating systems may not have cache coherency between mapped ;TI"buffers and file reads.;T: @fileI"io_buffer.c;T:0@omit_headings_from_table_of_contents_below0I"BIO::Buffer.map(file, [size, [offset, [flags]]]) -> io_buffer ;T0[ I"(*args);T@3FI"Buffer;TcRDoc::NormalClass00