Permalink
a97b191 Mar 24, 2016
@colesbury @andresy @nicholas-leonard @mvitez @keon
75 lines (51 sloc) 2.7 KB

DiskFile

Parent classes: File

A DiskFile is a particular File which is able to perform basic read/write operations on a file stored on disk. It implements all methods described in File, and some additional methods relative to endian encoding.

By default, a DiskFile is in ASCII mode. If changed to the binary mode, the default endian encoding is the native computer one.

The file might be open in read, write, or read-write mode, depending on the parameter mode (which can take the value "r", "w" or "rw" respectively) given to the torch.DiskFile(fileName, mode).

torch.DiskFile(fileName, [mode], [quiet])

Constructor which opens fileName on disk, using the given mode. Valid mode are "r" (read), "w" (write) or "rw" (read-write). Default is read mode.

If read-write mode, the file will be created if it does not exists. If it exists, it will be positioned at the beginning of the file after opening.

If (and only if) quiet is true, no error will be raised in case of problem opening the file: instead nil will be returned.

The file is opened in ASCII mode by default.

bigEndianEncoding()

In binary mode, force encoding in big endian. (big end first: decreasing numeric significance with increasing memory addresses)

[boolean] isBigEndianCPU()

Returns true if, and only if, the computer CPU operates in big endian. Big end first: decreasing numeric significance with increasing memory addresses.

[boolean] isLittleEndianCPU()

Returns true if, and only if, the computer CPU operates in little endian. Little end first: increasing numeric significance with increasing memory addresses.

littleEndianEncoding()

In binary mode, force encoding in little endian. (little end first: increasing numeric significance with increasing memory addresses)

nativeEndianEncoding()

In binary mode, force encoding in native endian.

longSize([size])

Longs will be written and read from the file as size bytes long, which can be 0, 4 or 8. 0 means system default.

noBuffer()

Disables read and write buffering on the DiskFile.