![]() |
![]() |
![]() |
|
![]() |
![]() |
![]() |
JavaScript File object proposal This documents describes a proposed API for the JavaScript File object. A lot of the API has been implemented (but not tested), and there is work yet to be done. Please send comments to mang@netscape.com. Many scripts in JavaScript require I/O capabilities and particularly access to normal files. This document describes such a File object that can be implemented by host implementations. The immediate goal is to provide normal file access, and later add Perl-like filehandle features. The design of the File object should allow these features to be added later on. The interface is a mix of the Server Side JS File object, the Java File object and tries to follow existing implicit JavaScript usage ( readln instead of readLine, for example ). The File object gives 2 way to access the data inside a file: a text oriented access, based on characters, and a binary oriented access, based on bytes. No provision for different encodings is provided. 1.0 FilenamesFilenames are specified as strings that have an implementation defined format. Use of standard "file:" URLs is encouraged. Examples of possible prefix strings are "/" to indicate the Unix root directory, "c:" to specify a Windows drive letter, and "file:" to indicate a file URL. Eventually we want to be able to do things like this: var mail = new File("|/usr/bin/mail foo@bar.com");
It should be possible to do this using the current API since filenames are platform dependent. 2.0 Properties of the File constructor
2.1 Properties of File instances
2.2 Instance methods
3.0 Properties of the File constructorA File object that represents the standard input. A File object that represents the standard input. A File object that represents the standard input. This property contains a File object pointing to the current directory. The system name separator. For example, "/" on Unix. 3.1 Properties of File instancesThis property contains the number of characters in the file. This property contains a File object pointing to the directory containing
the file.
This property contains the canonical path to the file. This property contains the name of the file. This property contains true if the file is a directory. This property contains true if the file is a regular data file. Note that on some platforms, both "isDirectory" and "isFile" may return false for some special type of files (for example, unix named pipes). This property equals true if the file exists. This property contains true if the file can be read. This property contains true if the file can be written. This property contains true if the file has been successfully opened and is still open. This property contains a string specifying the type of data or encoding
used when the file was opened.
This property contains a string of comma separated value specifying
the way this file is opened.
This property contains a Date object for the time the file was last modified. This property contains a flag indicating that the file is being opened
in random access mode.
This property contains the current offset in the file. this is the only property that may be set. This property has no meaning if the file is not in "randomAccess" mode. 3.1.1 Special properties for directoriesA File object that represents a directory gets additional properties that represent the files contained in the directory. These properties have the same names as the files in the directory.
3.2 Instance methods
If no mode is specified, the default mode is "read,append,create". If no type is specified, the default type is "text".
This method closes the file. This method deletes the file or removes the directory given as argument. Normally if remove is called on a directory it is only deleted if the directory is empty. If the optional recursive parameter is true, then the directory is always deleted, including any subdirectories. This method tries to make a raw copy of the source file into a destination
file.
This method moves/renames the file. This method forces to flush the output buffers of the file.
This methods skips the next numChars characters or bytes depending on the current access mode for the file. This method reads numChars characters and return them in a string. If there are less than numChars characters left to read, then the available characters are returned. If the file is at EOF, then null is returned. This methods reads characters until an end of line/file is encountered then returns the string for these characters (without any end of line character). This methods reads the rest of the file and returns an array with a slot for each line of the file. This method converts each arguments into a string, then writes it to the file (without separators). This method is similar to This method takes an array as an argument, and calls writeln() on each of them This method returns an array. if the file is a directory, an slot is created for each file inside that directory, and a property with the file name is created too. Both point to a File object referring to the file.
This method attempts to create a directory. If makeParents is not specified or is false, then no parent directories will be created. If makeParents is true, then parent directories will be created as necessary. This method returns the canonical path to the file. return the name of the file as a "file:" URL 4.0 I want to playFlaming disclaimer: Do not play with the File object if you are not prepared to have your hard drive erased, smashed, and broken into little bits! It mostly works right now, but no guarantees. Currently the File object can be built into the core JS engine using a define. This is wrong. Once XPCOM settles down, the File object should be COM-ified. To play with/hack on the File object, get the latest and greatest (usually) JavaScript using CVS:
Be warned that this gives you the active development branch for JavaScript, which offers few guarantees of stability. To build (the reference interpreter on UNIX in this example) with the
File object define
5.0 Unresolved questions/TODOExceptions should be generated when errors occur. What should the format of these be? Need to mark these errors. Should there be event handlers? XPCOM-ify. Mike Ang Last modified: Fri Dec 4 18:07:47 PST 1998
|
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright © 1998 The Mozilla Organization. |