back to io
wxFile
generated from ../src/mod_io/file.cpp
A wxFile performs raw file I/O.
This is a very small class designed to minimize the overhead of using it -
in fact, there is hardly any overhead at all, but using it brings you
automatic error checking and hides differences between platforms.
wxFile is a wrapper around a file descriptor, while wxFFile is a wrapper
around the FILE structure.
Constants
FileAccess
| Name |
Description |
| IRUSR |
|
| IWUSR |
|
| IXUSR |
|
| IRGRP |
|
| IWGRP |
|
| IXGRP |
|
| IROTH |
|
| IWOTH |
|
| IXOTH |
|
| DEFAULT |
|
FileDescriptor
| Name |
Description |
| fd_stdin |
|
| fd_stdout |
|
| fd_stderr |
|
Mode
| Name |
Description |
| read |
|
| write |
|
| read_write |
|
| write_append |
|
| write_excl |
|
wxFileKind
| Name |
Description |
| KIND_UNKNOWN |
|
| KIND_DISK |
|
| KIND_TERMINAL |
|
| KIND_PIPE |
|
wxSeekMode
| Name |
Description |
| FromCurrent |
|
| FromStart |
|
| FromEnd |
|
wxSeekMode is ported as a separate JavaScript object.
Class Methods
access
access(Filename,
Mode) : Boolean
| Name |
Type |
Default |
Description |
| Filename |
String |
|
Filename to check |
| Mode |
Mode |
|
File mode |
This function verifies if we may access the given file in specified mode.
Only values of read or write really make sense here.
exists
exists(Filename) : Boolean
| Name |
Type |
Default |
Description |
| Filename |
String |
|
|
Returns true when the file exists.
Constructor
wxFile
wxFile()
wxFile(FileName,
Mode = wxFile.read)
| Name |
Type |
Default |
Description |
| FileName |
String |
|
The filename |
| Mode |
OpenMode |
wxFile.read |
The mode in which to open the file. See Mode.
|
Constructs a new wxFile object. When a filename is passed,
The file is opened, and you can check whether the operation
was successful or not by checking opened.
Properties
| Name |
Type |
Description |
eof  |
Boolean |
Returns true when end of file is reached.
When the file is not open, undefined is returned.
|
length  |
Integer |
Returns the length of the file.
When the file is not open, undefined is returned.
|
opened  |
Boolean |
Returns true when the file is open.
|
tell  |
Integer |
Returns the current position or -1.
When the file is not open, undefined is returned.
|
Methods
attach
attach(Fd)
| Name |
Type |
Default |
Description |
| Fd |
Integer |
|
A file descriptor
|
Attaches an existing file descriptor to the wxFile object.
Example of predefined file descriptors are 0, 1 and 2 which correspond to
stdin, stdout and stderr (and have symbolic names of wxFile.fd_stdin, wxFile.fd_stdout
and wxFile.fd_stderr).
close
close()
Closes the file.
create
create(FileName,
Overwrite = false,
Access = wxFile.DEFAULT) : Boolean
| Name |
Type |
Default |
Description |
| FileName |
String |
|
The name of the file to create. |
| Overwrite |
Boolean |
false |
Overwrite the file when it already exist? The default is false.
|
| Access |
Integer |
wxFile.DEFAULT |
|
Creates a file for writing.
detach
detach()
Get back a file descriptor from wxFile object - the caller is responsible for closing
the file if this descriptor is opened. opened will return false
after call to detach.
flush
flush()
Flushes the file.
open
open(FileName,
Mode = wxFile.read) : Boolean
| Name |
Type |
Default |
Description |
| FileName |
String |
|
The name of the file to open |
| Mode |
Integer |
wxFile.read |
|
Opens a file.
read
read(Count) : wxMemoryBuffer
| Name |
Type |
Default |
Description |
| Count |
Integer |
|
The number of bytes to read. |
Reads the specified number of bytes and returns a buffer.
seek
seek(Offset,
Mode = wxFile.FromStart) : Integer
| Name |
Type |
Default |
Description |
| Offset |
Integer |
|
Offset to seek to. |
| Mode |
wxSeekMode |
wxFile.FromStart |
|
Seeks the offset. Returns the actual position or -1.
See also seekEnd.
seekEnd
seekEnd(Offset)
| Name |
Type |
Default |
Description |
| Offset |
Integer |
|
Offset to seek to. |
Moves the file pointer to the specified number of bytes before the end of the file.
Returns the actual position or -1 on error.
Remark: Is the same as calling seek(Offset, wxFile.FromEnd)
write
write(Buffer) : Integer
write(Str,
Encoding = UTF-8) : Integer
| Name |
Type |
Default |
Description |
| Str |
String |
|
|
| Encoding |
String |
UTF-8 |
|
Writes the string or buffer to the file. A String
is written in the specified encoding. The default is
UTF-8 because most files are still written as UTF-8
or ASCII. Returns the actual number of bytes written to the file.