class Tkrzw::File
Generic file implementation. All operations except for “open” and “close” are thread-safe; Multiple threads can access the same file concurrently. You can specify a concrete class when you call the “open” method. Every opened file must be closed explicitly by the “close” method to avoid data corruption.
Public Class Methods
Initializes the file object.
# File tkrzw.rb, line 1089 def initialize() # (native code) end
Public Instance Methods
Appends data at the end of the file.
-
@param data The data to write.
-
@param status A status object to which the result status is assigned. It can be omitted.
-
@return The offset at which the data has been put, or nil on failure.
# File tkrzw.rb, line 1147 def append(data, status=nil) # (native code) end
Closes the file.
-
@return The result status.
# File tkrzw.rb, line 1122 def close() # (native code) end
Releases the resource explicitly. The file is closed implicitly if it has not been closed. As long as you close the file explicitly, you don't have to call this method.
# File tkrzw.rb, line 1095 def destruct() # (native code) end
Gets the path of the file.
-
@return The path of the file or nil on failure.
# File tkrzw.rb, line 1177 def get_path() # (native code) end
Gets the size of the file.
-
@return The size of the file or nil on failure.
# File tkrzw.rb, line 1171 def get_size() # (native code) end
Returns a string representation of the object.
-
@return The string representation of the object.
# File tkrzw.rb, line 1198 def inspect() # (native code) end
Opens a file.
-
@param path A path of the file.
-
@param writable If true, the file is writable. If false, it is read-only.
-
@param params Optional keyword parameters.
-
@return The result status.
The optional parameters can include an option for the concurrency tuning. By default, database operatins are done under the GIL (Global Interpreter Lock), which means that database operations are not done concurrently even if you use multiple threads. If the “concurrent” parameter is true, database operations are done outside the GIL, which means that database operations can be done concurrently if you use multiple threads. However, the downside is that swapping thread data is costly so the actual throughput is often worse in the concurrent mode than in the normal mode. Therefore, the concurrent mode should be used only if the database is huge and it can cause blocking of threads in multi-thread usage. By default, the encoding of retrieved record data by the “get” method is implicitly set as “ASCII-8BIT”. If you want to change the implicit encoding to “UTF-8” or others, set the encoding name as the value of the “encoding” parameter. The optional parameters can include options for the file opening operation.
-
truncate (bool): True to truncate the file.
-
no_create (bool): True to omit file creation.
-
no_wait (bool): True to fail if the file is locked by another process.
-
no_lock (bool): True to omit file locking.
-
sync_hard (bool): True to do physical synchronization when closing.
The optional parameter “file” specifies the internal file implementation class. The default file class is “MemoryMapAtomicFile”. The other supported classes are “StdFile”, “MemoryMapAtomicFile”, “PositionalParallelFile”, and “PositionalAtomicFile”. For the file “PositionalParallelFile” and “PositionalAtomicFile”, these optional parameters are supported.
-
block_size (int): The block size to which all blocks should be aligned.
-
access_options (str): Values separated by colon. “direct” for direct I/O. “sync” for synchrnizing I/O, “padding” for file size alignment by padding, “pagecache” for the mini page cache in the process.
# File tkrzw.rb, line 1116 def open(path, writable, **params) # (native code) end
Reads data.
-
@param off The offset of a source region.
-
@param size The size to be read.
-
@param status A status object to which the result status is assigned. It can be omitted.
-
@return The read data or nil on failure.
# File tkrzw.rb, line 1131 def read(off, size, status=nil) # (native code) end
Searches the file and get lines which match a pattern.
-
@param mode The search mode. “contain” extracts lines containing the pattern. “begin” extracts lines beginning with the pattern. “end” extracts lines ending with the pattern. “regex” extracts lines partially matches the pattern of a regular expression. “edit” extracts lines whose edit distance to the UTF-8 pattern is the least. “editbin” extracts lines whose edit distance to the binary pattern is the least.
-
@param pattern The pattern for matching.
-
@param capacity The maximum records to obtain. 0 means unlimited.
-
@return A list of lines matching the condition.
# File tkrzw.rb, line 1186 def search(mode, pattern, capacity=0) # (native code) end
Synchronizes the content of the file to the file system.
-
@param hard True to do physical synchronization with the hardware or false to do only logical synchronization with the file system.
-
@param off The offset of the region to be synchronized.
-
@param size The size of the region to be synchronized. If it is zero, the length to the end of file is specified.
-
@return The result status.
The pysical file size can be larger than the logical size in order to improve performance by reducing frequency of allocation. Thus, you should call this function before accessing the file with external tools.
# File tkrzw.rb, line 1165 def synchronize(hard, off=0, size=0) # (native code) end
Returns a string representation of the content.
-
@return The string representation of the content.
# File tkrzw.rb, line 1192 def to_s() # (native code) end
Truncates the file.
-
@param size The new size of the file.
-
@return The result status.
If the file is shrunk, data after the new file end is discarded. If the file is expanded, null codes are filled after the old file end.
# File tkrzw.rb, line 1155 def truncate(size) # (native code) end
Writes data.
-
@param off The offset of the destination region.
-
@param data The data to write.
-
@return The result status.
# File tkrzw.rb, line 1139 def write(off, data) # (native code) end