The IO module ports the IO related classes of wxWidgets to JavaScript:


wxJavaScript provides some functions and classes to facilitate working with files.

wxFile and wxFFile may be used for low-level IO. It contains all the usual functions to work with files (opening/closing, reading/writing, seeking, and so on) and closes the file automatically when the object is garbage collected.

wxTempFile is a very small class designed to make replacing the files contents safer - see its documentation for more details.

wxTextFile is a general purpose class for working with small text files on line by line basis. It is especially well suited for working with configuration files and program source files. It can be also used to work with files with "non native" line termination characters and write them as "native" files if needed (in fact, the files may be written in any format).

wxDir is a helper class for enumerating the files or subdirectories of a directory. It may be used to enumerate all files, only files satisfying the given template mask or only non-hidden files.


Streams are divided in two main parts:

wxStreamBase is the base definition of a stream. wxInputStream is the base class for read-only streams. It implements Read, SeekI (I for Input), and all read or IO generic related functions. wxOutputStream does the same thing but it is for write-only streams.

The "IO" classes implements the specific parts of the stream.

Zip Archives

Creating an archive

Call putNextEntry to create a new entry in the archive. Then write the entry's data into the stream. When you add files, you can use the method read from wxFileInputStream.

var zos = new wxZipOutputStream(new wxFileOutputStream(""));
var entry = new wxZipEntry(filename);

var fis = new wxFileInputStream(filename);
var bfs = new wxBufferedOutputStream(zos);;

// Don't forget to sync (flush), otherwise you loose content

Extracting an archive

Use the property nextEntry of the wxZipInputStream class. When you start reading from this input stream, you 'll get the data of the entry. When eof is reached, you've got all the data. You can also use the read method to pass the data to an output stream like wxMemoryOutputStream.

var fis = new wxFileInputStream("");
if ( fis.ok )
  var zis = new wxZipInputStream(fis);
  wxMessageBox(zis.totalEntries + ' ' + zis.comment);

  var entry = zis.nextEntry;
    var mos = new wxMemoryOutputStream();;

    entry = zis.nextEntry;    

Design downloaded from Free website templates, layouts, and tools.