All Projects → perry-mitchell → Webdav Fs

perry-mitchell / Webdav Fs

Licence: mit
Node fs wrapper for WebDAV

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webdav Fs

Gowebdav
A golang WebDAV client library and command line tool.
Stars: ✭ 97 (+34.72%)
Mutual labels:  webdav, client
Request
go request, go http client
Stars: ✭ 105 (+45.83%)
Mutual labels:  request, client
Webdav Client Cpp
☁️ C++ WebDAV Client provides easy and convenient to work with WebDAV-servers.
Stars: ✭ 92 (+27.78%)
Mutual labels:  webdav, client
Restrequest4delphi
API to consume REST services written in any programming language with support to Lazarus and Delphi
Stars: ✭ 162 (+125%)
Mutual labels:  request, client
Bitcoin Core
A modern Bitcoin Core REST and RPC client.
Stars: ✭ 379 (+426.39%)
Mutual labels:  request, client
Distribyted
📂 ➡️ 📺 🎶 🎮 Torrent client with on-demand file downloading as a filesystem.
Stars: ✭ 791 (+998.61%)
Mutual labels:  webdav, filesystem
Vscode Remote Workspace
Multi protocol support for handling remote files like local ones in Visual Studio Code.
Stars: ✭ 197 (+173.61%)
Mutual labels:  webdav, filesystem
kodbox
kodbox is a file manager for web. It is a newly designed product based on kodexplorer. It is also a web code editor, which allows you to develop websites directly within the web browser.You can run kodbox either online or locally,on Linux, Windows or Mac based platforms
Stars: ✭ 1,188 (+1550%)
Mutual labels:  filesystem, webdav
electron-request
Zero-dependency, Lightweight HTTP request client for Electron or Node.js
Stars: ✭ 45 (-37.5%)
Mutual labels:  client, request
Webdav
Simple Go WebDAV server.
Stars: ✭ 630 (+775%)
Mutual labels:  webdav, filesystem
Guzzlette
🌀 Guzzle integration into Nette Framework (@nette)
Stars: ✭ 19 (-73.61%)
Mutual labels:  request, client
Pam radius
This is the PAM to RADIUS authentication module. It allows any Linux, OSX or Solaris machine to become a RADIUS client for authentication and password change requests.
Stars: ✭ 69 (-4.17%)
Mutual labels:  client
Fast Glob
🚀 It's a very fast and efficient glob library for Node.js
Stars: ✭ 1,150 (+1497.22%)
Mutual labels:  filesystem
Sao
Mirror of Tryton web client - Sao
Stars: ✭ 67 (-6.94%)
Mutual labels:  client
Includedir
Include a whole directory tree at compile time
Stars: ✭ 67 (-6.94%)
Mutual labels:  filesystem
Css Vars Ponyfill
Client-side support for CSS custom properties (aka "CSS variables") in legacy and modern browsers
Stars: ✭ 1,166 (+1519.44%)
Mutual labels:  client
Webdavfs
Linux / OSX FUSE webdav filesystem. This filesystem behaves like a real network filesystem- no unnecessary copying of entire files.
Stars: ✭ 69 (-4.17%)
Mutual labels:  webdav
Kaidan
[Replaced by https://invent.kde.org/network/kaidan] Kaidan, a simple and user-friendly Jabber/XMPP client for every device and platform.
Stars: ✭ 67 (-6.94%)
Mutual labels:  client
Cti Taxii Client
OASIS TC Open Repository: TAXII 2 Client Library Written in Python
Stars: ✭ 67 (-6.94%)
Mutual labels:  client
Dimscord
A Discord Bot & REST Library for Nim.
Stars: ✭ 67 (-6.94%)
Mutual labels:  client

WebDAV-fs

Node fs wrapper for WebDAV. Perform basic filesystem tasks in a similar manner to using async fs methods like readdir and writeFile. webdav-fs uses webdav-client under the hood.

Build Status npm version npm downloads

Installation

Install webdav-fs using npm:

npm install webdav-fs --save

Supports NodeJS 10 and above. For Node 8 support, use v2.

Examples

You can use webdav-fs in authenticated or non-authenticated mode:

// Using authentication:
var wfs = require("webdav-fs")("http://example.com/webdav/", {
    username: "username",
    password: "password"
});

wfs.readdir("/Work", function(err, contents) {
    if (!err) {
        console.log("Dir contents:", contents);
    } else {
        console.log("Error:", err.message);
    }
});
// Without using authentication:
var wfs = require("webdav-fs")("http://example.com/webdav/");

wfs.stat("/report.docx", function(err, data) {
    console.log("Is file:", data.isFile());
});

For more control over the HTTP/TLS connection options, you can pass an instance of http.Agent or https.Agent:

var agent = require("https").Agent({
    keepAlive: true
    // we can also control certificate verification behaviour here
});

var wfs = require("webdav-fs")("https://example.com/webdav/", {
    username: "username",
    password: "password",
    httpsAgent: agent
});

API

You can read the API documentation here, or check out the examples below.

The following methods are available on the webdav-fs module:

createReadStream(path[, options])

Create a read stream on a remote file:

wfs
    .createReadStream("/dir/somefile.dat")
    .pipe(fs.createWriteStream("./somefile.dat"));

The options object supports overriding remote headers as well as a range (start and end as byte indexes). When specifying a range, only the start value is required (if end is not provided the rest of the file is read).

The following requests the first 300 bytes of a file:

var myPartialStream = wfs.createReadStream("/dir/somefile.dat", { start: 0, end: 299 });

createWriteStream(path[, options])

Create a write stream for a remote file:

fs
    .createReadStream("./myFile.dat")
    .pipe(wfs.createWriteStream("/data/myFile.dat"));

The options object supports overriding remote headers.

mkdir(path, callback)

Create a remote directory:

wfs.mkdir("/remote/dir", function(err) {
    // handle error if truthy
});

readdir(path[, mode], callback)

Read the contents of a remote directory:

wfs.readdir("/some/remote/path/", "node", function(err, contents) {
    // callback is an array of filenames
});

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.readFile("/website/index.php", "utf8", function(err, data) {
    // data is the contents of the file
    // encoding is optional
});

encoding is optional and can be either utf8 (default - returns a string) or binary (returns a Buffer).

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.rename("/my-document.docx", "/Documents/personal.docx", function (err) {
    // handle error
});

stat(path, callback)

Stat a remote file:

wfs.stat("/the-internet.dat", function(err, fileStat) {
    console.log(fileStat);
});

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.unlink("/remote/path", function(err) {
    // handle error if truthy
});

writeFile(path, data, [encoding,] callback)

Write data to a remote file:

wfs.writeFile("/Temp/im-here.txt", "This is a saved file! REALLY!!", function(err) {
    if (err) {
        console.error(err.message);
    }
});

writeFile supports writing binary files as well:

fs.readFile(sourceFile, "binary", function(err, data) {
    wfs.writeFile(destFile, data, "binary", function(err) {
        // handle error
    });
});

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.

Usage

Overriding the built-in fetch function

Under the hood, webdav-client uses node-fetch to perform requests. This can be overridden by running the following:

// For example, use the `fetch` method in the browser:
const createWebDAVfs = require("webdav-fs");
createWebDAVfs.setFetchMethod(window.fetch);

Refer to webdav-client's documentation for more information.

Browser usage and CORS

This library isn't exactly designed for use within the browser, although it might work if bundled using a tool like Webpack.

When in the browser take care with policies such as CORS - If the server is not configured correctly WebDAV requests will fail. Make sure that you return the correct CORS headers. Issues surrounding CORS errors without any indication that an error lies in this library will be closed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].