Class: CZMQ::FFI::Zfile
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zfile
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zfile.rb
Overview
This class is 100% generated using zproject.
helper functions for working with files.
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.new(path, name) ⇒ CZMQ::Zfile
If file exists, populates properties.
-
.test(verbose) ⇒ void
Self test of this class.
-
.tmp ⇒ CZMQ::Zfile
Create new temporary file for writing via tmpfile.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#close ⇒ void
Close file, if open.
-
#cursize ⇒ ::FFI::Pointer
Return the last-known size of the file.
-
#destroy ⇒ void
Destroy a file item.
-
#digest ⇒ String
Calculate SHA1 digest for file, using zdigest class.
-
#dup ⇒ Zfile
Duplicate a file item, returns a newly constructed item.
-
#eof ⇒ Boolean
Returns true if zfile_read() just read the last chunk in the file.
-
#filename(path) ⇒ String
Return file name, remove path if provided.
-
#handle ⇒ ::FFI::Pointer
Return file handle, if opened.
-
#has_changed ⇒ Boolean
Return true if the file was changed on disk since the zfile_t object was created, or the last zfile_restat() call made on it.
-
#initialize(ptr, finalize = true) ⇒ Zfile
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#input ⇒ Integer
Open file for reading Returns 0 if OK, -1 if not found or not accessible.
-
#is_directory ⇒ Boolean
Return true if the file is a directory.
-
#is_readable ⇒ Boolean
Return true if the file is readable by this process.
-
#is_regular ⇒ Boolean
Return true if the file is a regular file.
-
#is_stable ⇒ Boolean
Check if file has stopped changing and can be safely processed.
-
#is_writeable ⇒ Boolean
Return true if the file is writeable by this process.
-
#modified ⇒ ::FFI::Pointer
Return when the file was last modified.
- #null? ⇒ Boolean
-
#output ⇒ Integer
Open file for writing, creating directory if needed File is created if necessary; chunks can be written to file at any location.
-
#read(bytes, offset) ⇒ Zchunk
Read chunk from file at specified position.
-
#readln ⇒ String
Read next line of text from file.
-
#remove ⇒ void
Remove the file from disk.
-
#restat ⇒ void
Refresh file properties from disk; this is not done automatically on access methods, otherwise it is not possible to compare directory snapshots.
-
#write(chunk, offset) ⇒ Integer
Write chunk to file at specified position Return 0 if OK, else -1.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zfile
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zfile_destroy ptr_ptr end end |
.new(path, name) ⇒ CZMQ::Zfile
If file exists, populates properties. CZMQ supports portable symbolic links, which are files with the extension “.ln”. A symbolic link is a text file containing one line, the filename of a target file. Reading data from the symbolic link actually reads from the target file. Path may be NULL, in which case it is not used.
85 86 87 88 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 85 def self.new(path, name) ptr = ::CZMQ::FFI.zfile_new(path, name) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#close ⇒ void
This method returns an undefined value.
Close file, if open
319 320 321 322 323 324 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 319 def close() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_close(self_p) result end |
#cursize ⇒ ::FFI::Pointer
Return the last-known size of the file. If you want this to reflect the current situation, call zfile_restat before checking this property.
158 159 160 161 162 163 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 158 def cursize() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_cursize(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a file item
101 102 103 104 105 106 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 101 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zfile_destroy(self_p) result end |
#digest ⇒ String
Calculate SHA1 digest for file, using zdigest class.
339 340 341 342 343 344 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 339 def digest() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_digest(self_p) result end |
#dup ⇒ Zfile
Duplicate a file item, returns a newly constructed item. If the file is null, or memory was exhausted, returns null.
112 113 114 115 116 117 118 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 112 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_dup(self_p) result = Zfile.__new result, true result end |
#eof ⇒ Boolean
Returns true if zfile_read() just read the last chunk in the file.
284 285 286 287 288 289 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 284 def eof() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_eof(self_p) result end |
#filename(path) ⇒ String
Return file name, remove path if provided
124 125 126 127 128 129 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 124 def filename(path) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_filename(self_p, path) result end |
#handle ⇒ ::FFI::Pointer
Return file handle, if opened
329 330 331 332 333 334 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 329 def handle() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_handle(self_p) result end |
#has_changed ⇒ Boolean
Return true if the file was changed on disk since the zfile_t object was created, or the last zfile_restat() call made on it.
226 227 228 229 230 231 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 226 def has_changed() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_has_changed(self_p) result end |
#input ⇒ Integer
Open file for reading Returns 0 if OK, -1 if not found or not accessible
247 248 249 250 251 252 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 247 def input() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_input(self_p) result end |
#is_directory ⇒ Boolean
Return true if the file is a directory. If you want this to reflect any external changes, call zfile_restat before checking this property.
169 170 171 172 173 174 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 169 def is_directory() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_is_directory(self_p) result end |
#is_readable ⇒ Boolean
Return true if the file is readable by this process. If you want this to reflect any external changes, call zfile_restat before checking this property.
192 193 194 195 196 197 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 192 def is_readable() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_is_readable(self_p) result end |
#is_regular ⇒ Boolean
Return true if the file is a regular file. If you want this to reflect any external changes, call zfile_restat before checking this property.
180 181 182 183 184 185 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 180 def is_regular() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_is_regular(self_p) result end |
#is_stable ⇒ Boolean
Check if file has stopped changing and can be safely processed. Updates the file statistics from disk at every call.
215 216 217 218 219 220 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 215 def is_stable() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_is_stable(self_p) result end |
#is_writeable ⇒ Boolean
Return true if the file is writeable by this process. If you want this to reflect any external changes, call zfile_restat before checking this property.
204 205 206 207 208 209 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 204 def is_writeable() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_is_writeable(self_p) result end |
#modified ⇒ ::FFI::Pointer
Return when the file was last modified. If you want this to reflect the current situation, call zfile_restat before checking this property.
147 148 149 150 151 152 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 147 def modified() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_modified(self_p) result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 44 def null? !@ptr or @ptr.null? end |
#output ⇒ Integer
Open file for writing, creating directory if needed File is created if necessary; chunks can be written to file at any location. Returns 0 if OK, -1 if error.
259 260 261 262 263 264 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 259 def output() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_output(self_p) result end |
#read(bytes, offset) ⇒ Zchunk
Read chunk from file at specified position. If this was the last chunk, sets the eof property. Returns a null chunk in case of error.
272 273 274 275 276 277 278 279 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 272 def read(bytes, offset) raise DestroyedError unless @ptr self_p = @ptr bytes = Integer(bytes) result = ::CZMQ::FFI.zfile_read(self_p, bytes, offset) result = Zchunk.__new result, true result end |
#readln ⇒ String
Read next line of text from file. Returns a pointer to the text line, or NULL if there was nothing more to read from the file.
309 310 311 312 313 314 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 309 def readln() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_readln(self_p) result end |
#remove ⇒ void
This method returns an undefined value.
Remove the file from disk
236 237 238 239 240 241 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 236 def remove() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_remove(self_p) result end |
#restat ⇒ void
This method returns an undefined value.
Refresh file properties from disk; this is not done automatically on access methods, otherwise it is not possible to compare directory snapshots.
136 137 138 139 140 141 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 136 def restat() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zfile_restat(self_p) result end |
#write(chunk, offset) ⇒ Integer
Write chunk to file at specified position Return 0 if OK, else -1
297 298 299 300 301 302 303 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zfile.rb', line 297 def write(chunk, offset) raise DestroyedError unless @ptr self_p = @ptr chunk = chunk.__ptr if chunk result = ::CZMQ::FFI.zfile_write(self_p, chunk, offset) result end |