webdav-fs
Node fs
wrapper for WebDAV. Perform basic filesystem tasks in a similar manner to using async fs
methods like readdir
and writeFile
.
Installation
Install webdav-fs using npm:
npm install webdav-fs --save
Example
You can use webdav-fs in authenticated or non-authenticated mode:
// Using authentication:var wfs = "http://example.com/webdav/" "username" "password" ; wfs;
// Without using authentication:var wfs = "http://example.com/webdav/"; wfs;
API
The following methods are available on the webdav-fs
module:
mkdir(path, callback)
Create a remote directory:
wfs;
readdir(path, callback[, mode])
Read the contents of a remote directory:
wfs;
mode
is an optional processing mode, where:
- 'node' (the default mode) will output an array of filename strings
- 'stat' will output an array of stat objects (plus a
name
field)
readFile(path, [encoding,] callback)
Read the contents of a remote file:
wfs;
rename(currentPath, destinationPath, callback)
Move/rename a file to another location/name. This does not create new directories for nested files (moving a file into a new directory will not work).
wfs;
stat(path, callback)
Stat a remote file:
wfs;
A stat has the following properties:
Property | Type | Description |
---|---|---|
isFile | Function | Check if the item is a file |
isDirectory | Function | Check if the item is a directory |
mtime | Number | Last modification timestamp |
size | Number | Size of the item in bytes |
unlink(path, callback)
Delete a remote file or directory:
wfs;
writeFile(path, data, [encoding,] callback)
Write data to a remote file:
wfs;
writeFile
supports writing binary files as well:
fs;
writeFile
supports just a couple of encodings:
- utf8
- binary
When writing binary files, data must either be a binary string from a read file in Node (then passed to new Buffer(data, "binary")
) or a Buffer.