mirror of https://github.com/vitalif/phantomjs
Merge pull request #115 from detro/dev-commonjs_fileio
Completed implementation of "fs" basic modules1.3
commit
5adc92aec0
|
@ -88,7 +88,16 @@ window.WebPage = function() {
|
||||||
return page;
|
return page;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make "fs.open" throw an exception in case it fails
|
// window.fs
|
||||||
|
// JavaScript "shim" to throw exceptions in case a critical operation fails.
|
||||||
|
|
||||||
|
/** Open and return a "file" object.
|
||||||
|
* It will throw exception if it fails.
|
||||||
|
*
|
||||||
|
* @param path Path of the file to open
|
||||||
|
* @param mode Open Mode. A string made of 'r', 'w', 'a/+' characters.
|
||||||
|
* @return "file" object
|
||||||
|
*/
|
||||||
window.fs.open = function(path, mode) {
|
window.fs.open = function(path, mode) {
|
||||||
var file = window.fs._open(path, mode);
|
var file = window.fs._open(path, mode);
|
||||||
if (file) {
|
if (file) {
|
||||||
|
@ -96,3 +105,31 @@ window.fs.open = function(path, mode) {
|
||||||
}
|
}
|
||||||
throw "Unable to open file '"+ path +"'";
|
throw "Unable to open file '"+ path +"'";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Open, read and return content of a file.
|
||||||
|
* It will throw an exception if it fails.
|
||||||
|
*
|
||||||
|
* @param path Path of the file to read from
|
||||||
|
* @return file content
|
||||||
|
*/
|
||||||
|
window.fs.read = function(path) {
|
||||||
|
var f = fs.open(path, 'r'),
|
||||||
|
content = f.read();
|
||||||
|
|
||||||
|
f.close();
|
||||||
|
return content;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Open and write content to a file
|
||||||
|
* It will throw an exception if it fails.
|
||||||
|
*
|
||||||
|
* @param path Path of the file to read from
|
||||||
|
* @param content Content to write to the file
|
||||||
|
* @param mode Open Mode. A string made of 'w' or 'a / +' characters.
|
||||||
|
*/
|
||||||
|
window.fs.write = function(path, content, mode) {
|
||||||
|
var f = fs.open(path, mode);
|
||||||
|
|
||||||
|
f.write(content);
|
||||||
|
f.close();
|
||||||
|
};
|
||||||
|
|
|
@ -70,25 +70,53 @@ public:
|
||||||
FileSystem(QObject *parent = 0);
|
FileSystem(QObject *parent = 0);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool exists(const QString &path) const;
|
// Attributes
|
||||||
bool isDirectory(const QString &path) const;
|
// - int size(const QString &path) const; //< TODO - in bytes, or throw excep if doesn't exists
|
||||||
bool isFile(const QString &path) const;
|
// - QDateTime lastModified(const QString &path) const; //< TODO - returns the time that a file was last modified as a Date object.
|
||||||
|
|
||||||
|
// Files / Directories
|
||||||
|
// - copy()
|
||||||
|
// - move()
|
||||||
|
// - touch(path, date)
|
||||||
|
// - rename()
|
||||||
|
|
||||||
|
// Directory
|
||||||
|
// - copyTree(source, target) //< copies files from a source path to a target path,
|
||||||
|
// copying the files of the source tree to the corresponding locations
|
||||||
|
// relative to the target, copying but not traversing into
|
||||||
|
// symbolic links to directories.
|
||||||
bool makeDirectory(const QString &path) const;
|
bool makeDirectory(const QString &path) const;
|
||||||
bool makeTree(const QString &path) const;
|
bool makeTree(const QString &path) const;
|
||||||
|
|
||||||
bool remove(const QString &path) const;
|
|
||||||
bool removeDirectory(const QString &path) const;
|
bool removeDirectory(const QString &path) const;
|
||||||
bool removeTree(const QString &path) const;
|
bool removeTree(const QString &path) const;
|
||||||
|
|
||||||
|
// Files
|
||||||
|
// 'open(path, mode)' implemented in "bootstrap.js" JavaScript shim, using '_open(path, mode)'
|
||||||
|
QObject *_open(const QString &path, const QString &mode) const;
|
||||||
|
// 'read(path)' implemented in "bootstrap.js" JavaScript shim
|
||||||
|
// 'write(path, mode)' implemented in the "bootstrap.js" JavaScript shim
|
||||||
|
|
||||||
|
bool remove(const QString &path) const;
|
||||||
|
|
||||||
|
// Listing
|
||||||
QStringList list(const QString &path) const;
|
QStringList list(const QString &path) const;
|
||||||
|
|
||||||
|
// Paths
|
||||||
|
QString separator() const;
|
||||||
QString workingDirectory() const;
|
QString workingDirectory() const;
|
||||||
bool changeWorkingDirectory(const QString &path) const;
|
bool changeWorkingDirectory(const QString &path) const;
|
||||||
|
// - absolute(relative_path)
|
||||||
|
|
||||||
QString separator() const;
|
// Tests
|
||||||
|
bool exists(const QString &path) const;
|
||||||
QObject *_open(const QString &path, const QString &mode) const;
|
bool isDirectory(const QString &path) const;
|
||||||
|
bool isFile(const QString &path) const;
|
||||||
|
// - isAbsolute()
|
||||||
|
// - isExecutable()
|
||||||
|
// - isLink()
|
||||||
|
// - isMount()
|
||||||
|
// - isReadable()
|
||||||
|
// - isWritable()
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FILESYSTEM_H
|
#endif // FILESYSTEM_H
|
||||||
|
|
Loading…
Reference in New Issue