D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Buffer
/
Filename :
copy-i.ri
back
Copy
U:RDoc::AnyMethod[iI" copy:ETI"IO::Buffer#copy;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"LEfficiently copy from a source IO::Buffer into the buffer, at +offset+ ;TI"Dusing +memmove+. For copying String instances, see #set_string.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"!buffer = IO::Buffer.new(32) ;TI" # => ;TI"4# #<IO::Buffer 0x0000555f5ca22520+32 INTERNAL> ;TI"T# 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ ;TI"W# 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ * ;TI" ;TI",buffer.copy(IO::Buffer.for("test"), 8) ;TI"%# => 4 -- size of buffer copied ;TI"buffer ;TI" # => ;TI"4# #<IO::Buffer 0x0000555f5cf8fe40+32 INTERNAL> ;TI"T# 0x00000000 00 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00 ........test.... ;TI"V# 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ * ;T:@format0o; ; [I"I#copy can be used to put buffer into strings associated with buffer:;T@o;; [ I"string = "data: " ;TI"# => "data: " ;TI"1buffer = IO::Buffer.for(string) do |buffer| ;TI". buffer.copy(IO::Buffer.for("test"), 5) ;TI" end ;TI"# => 4 ;TI"string ;TI"# => "data:test" ;T; 0o; ; [I"7Attempt to copy into a read-only buffer will fail:;T@o;; [ I"$File.write('test.txt', 'test') ;TI"Rbuffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY) ;TI",buffer.copy(IO::Buffer.for("test"), 8) ;TI"D# in `copy': Buffer is not writable! (IO::Buffer::AccessError) ;T; 0o; ; [I"KSee ::map for details of creation of mutable file mappings, this will ;TI" work:;T@o;; [ I":buffer = IO::Buffer.map(File.open('test.txt', 'r+')) ;TI",buffer.copy(IO::Buffer.for("boom"), 0) ;TI"# => 4 ;TI"File.read('test.txt') ;TI"# => "boom" ;T; 0o; ; [I"JAttempt to copy the buffer which will need place outside of buffer's ;TI"bounds will fail:;T@o;; [I" buffer = IO::Buffer.new(2) ;TI",buffer.copy(IO::Buffer.for('test'), 0) ;TI"Z# in `copy': Specified offset+length is bigger than the buffer size! (ArgumentError) ;T; 0o; ; [I"IIt is safe to copy between memory regions that overlaps each other. ;TI"`In such case, the data is copied as if the data was first copied from the source buffer to ;TI"]a temporary buffer, and then copied from the temporary buffer to the destination buffer.;T@o;; [ I"!buffer = IO::Buffer.new(10) ;TI"%buffer.set_string("0123456789") ;TI"buffer.copy(buffer, 3, 7) ;TI"# => 7 ;TI"buffer ;TI" # => ;TI"4# #<IO::Buffer 0x000056494f8ce440+10 INTERNAL> ;TI"M# 0x00000000 30 31 32 30 31 32 33 34 35 36 0120123456;T; 0: @fileI"io_buffer.c;T:0@omit_headings_from_table_of_contents_below0I"?copy(source, [offset, [length, [source_offset]]]) -> size ;T0[ I"(*args);T@XFI"Buffer;TcRDoc::NormalClass00