X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=documentation%2Fapi%2Fmodules%2Fnixio.File.html;fp=documentation%2Fapi%2Fmodules%2Fnixio.File.html;h=c4f9ab86666c50dbb0a12211591ec694af71639e;hp=0000000000000000000000000000000000000000;hb=00e2b03927b5c107aefef1c71ef14facd4c3cb77;hpb=ed1a6416964df17b3a76a7043734d0fde4a6bd41 diff --git a/documentation/api/modules/nixio.File.html b/documentation/api/modules/nixio.File.html new file mode 100644 index 000000000..c4f9ab866 --- /dev/null +++ b/documentation/api/modules/nixio.File.html @@ -0,0 +1,641 @@ + + + + Reference + + + + + +
+ +
+ +
+
+
+ +
+ + + +
+ +

Object Instance nixio.File

+ +

+ Large File Object. + Large file operations are supported up to 52 bits if the Lua number type is + double (default).

+ + + + + + + +

Functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
File:close () + Close the file descriptor.
File:fileno () + Get the number of the filedescriptor.
File:lock (command, length) + Apply or test a lock on the file.
File:read (length) + Read from a file descriptor.
File:seek (offset, whence) + Reposition read / write offset of the file descriptor.
File:setblocking (blocking) + (POSIX) Set the blocking mode of the file descriptor.
File:stat (field) + Get file status and attributes.
File:sync (data_only) + Synchronizes the file with the storage device.
File:tell () + Return the current read / write offset of the file descriptor.
File:write (buffer, offset, length) + Write to the file descriptor.
+ + + + + + +
+
+ + +

Functions

+
+ + + +
File:close ()
+
+ + Close the file descriptor. + + + + + + + +

Return value:

+true + + + +
+ + + + +
File:fileno ()
+
+ + Get the number of the filedescriptor. + + + + + + + +

Return value:

+file descriptor number + + + +
+ + + + +
File:lock (command, length)
+
+ + Apply or test a lock on the file. + + +

Parameters

+
    + +
  • + command: Locking Command ["lock", "tlock", "ulock", "test"] +
  • + +
  • + length: Amount of Bytes to lock from current offset (optional) +
  • + +
+ + + + +

Usage

+
    + +
  • This function calls lockf() on POSIX and _locking() on Windows. + +
  • The "lock" command is blocking, "tlock" is non-blocking, + "ulock" unlocks and "test" only tests for the lock. + +
  • The "test" command is not available on Windows. + +
  • Locks are by default advisory on POSIX, but mandatory on Windows. + +
+ + + +

Return value:

+true + + + +
+ + + + +
File:read (length)
+
+ + Read from a file descriptor. + + +

Parameters

+
    + +
  • + length: Amount of data to read (in Bytes). +
  • + +
+ + + + +

Usage

+
    + +
  • Warning: It is not guaranteed that all requested data + is read at once especially when dealing with pipes. + You have to check the return value - the length of the buffer actually read - + or use the safe IO functions in the high-level IO utility module. + +
  • The length of the return buffer is limited by the (compile time) + nixio buffersize which is nixio.const.buffersize (8192 by default). + Any read request greater than that will be safely truncated to this value. + +
+ + + +

Return value:

+buffer containing data successfully read + + + +
+ + + + +
File:seek (offset, whence)
+
+ + Reposition read / write offset of the file descriptor. + The seek will be done either from the beginning of the file or relative + to the current position or relative to the end. + + +

Parameters

+
    + +
  • + offset: File Offset +
  • + +
  • + whence: Starting point ["set", "cur", "end"] +
  • + +
+ + + + +

Usage:

+This function calls lseek(). + + + +

Return value:

+new (absolute) offset position + + + +
+ + + + +
File:setblocking (blocking)
+
+ + (POSIX) Set the blocking mode of the file descriptor. + + +

Parameters

+
    + +
  • + blocking: (boolean) +
  • + +
+ + + + + + +

Return value:

+true + + + +
+ + + + +
File:stat (field)
+
+ + Get file status and attributes. + + +

Parameters

+
    + +
  • + field: Only return a specific field, not the whole table (optional) +
  • + +
+ + + + +

Usage:

+This function calls fstat(). + + + +

Return value:

+Table containing:
    +
  • atime = Last access timestamp
  • +
  • blksize = Blocksize (POSIX only)
  • +
  • blocks = Blocks used (POSIX only)
  • +
  • ctime = Creation timestamp
  • +
  • dev = Device ID
  • +
  • gid = Group ID
  • +
  • ino = Inode
  • +
  • modedec = Mode converted into a decimal number
  • +
  • modestr = Mode as string as returned by ls -l
  • +
  • mtime = Last modification timestamp
  • +
  • nlink = Number of links
  • +
  • rdev = Device ID (if special file)
  • +
  • size = Size in bytes
  • +
  • type = ["reg", "dir", "chr", "blk", "fifo", "lnk", "sock"]
  • +
  • uid = User ID
  • +
+ + + +
+ + + + +
File:sync (data_only)
+
+ + Synchronizes the file with the storage device. + Returns when the file is successfully written to the disk. + + +

Parameters

+
    + +
  • + data_only: Do not synchronize the metadata. (optional, boolean) +
  • + +
+ + + + +

Usage

+
    + +
  • This function calls fsync() when data_only equals false + otherwise fdatasync(), on Windows _commit() is used instead. + +
  • fdatasync() is only supported by Linux and Solaris. For other systems + the data_only parameter is ignored and fsync() is always called. + +
+ + + +

Return value:

+true + + + +
+ + + + +
File:tell ()
+
+ + Return the current read / write offset of the file descriptor. + + + + + +

Usage:

+This function calls lseek() with offset 0 from the current position. + + + +

Return value:

+offset position + + + +
+ + + + +
File:write (buffer, offset, length)
+
+ + Write to the file descriptor. + + +

Parameters

+
    + +
  • + buffer: Buffer holding the data to be written. +
  • + +
  • + offset: Offset to start reading the buffer from. (optional) +
  • + +
  • + length: Length of chunk to read from the buffer. (optional) +
  • + +
+ + + + +

Usage

+
    + +
  • Warning: It is not guaranteed that all data + in the buffer is written at once especially when dealing with pipes. + You have to check the return value - the number of bytes actually written - + or use the safe IO functions in the high-level IO utility module. + +
  • Unlike standard Lua indexing the lowest offset and default is 0. + +
+ + + +

Return value:

+number of bytes written + + + +
+ + +
+ + + + + +
+ +
+ +
+

Valid XHTML 1.0!

+
+ +
+ +