New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webdav

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webdav

WebDAV client for NodeJS

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
increased by6.7%
Maintainers
1
Weekly downloads
 
Created
Source

WebDAV client

A WebDAV client written in JavaScript for NodeJS.

Build Status

About

This client was branched from webdav-fs as the core functionality deserved its own repository. As webdav-fs' API was designed to resemble NodeJS' fs API, little could be done to improve the adapter interface for regular use.

This WebDAV client library is designed to provide an improved API for low-level WebDAV integration.

Usage

Usage is very simple - the main exported object is a factory to create adapter instances:

var createClient = require("webdav");

var client = createClient(
    "https://webdav-server.org/remote.php/webdav",
    "username",
    "password"
);

client
    .getDirectoryContents("/")
    .then(function(contents) {
        console.log(JSON.stringify(contents, undefined, 4));
    })
    .catch(function(err) {
        console.error(err);
    });

Each method returns a Promise.

Adapter methods

These methods can be called on the object returned from the main factory.

createDirectory(remotePath)

Create a new directory at the remote path.

deleteFile(remotePath)

Delete a file or directory at remotePath.

getDirectoryContents(remotePath)

Get an array of items within a directory. remotePath is a string that begins with a forward-slash and indicates the remote directory to get the contents of.

client
    .getDirectoryContents("/MyFolder")
    .then(function(contents) {
        console.log(JSON.stringify(contents, undefined, 2));
    })
    .catch(function(err) {
        console.error(err);
    });

The returned value is a Promise, which resolves with an array of item stat objects.

getFileContents(remotePath, format)

Get the contents of the file at remotePath as a Buffer or String. format can either be "binary" or "text", where "binary" is default.

var fs = require("fs");

client
    .getFileContents("/folder/myImage.jpg")
    .then(function(imageData) {
        fs.writeFileSync("./myImage.jpg", imageData);
    })
    .catch(function(err) {
        console.error(err);
    });

Or with text:

client
    .getFileContents("/doc.txt", "text")
    .then(function(text) {
        console.log(text);
    })
    .catch(function(err) {
        console.error(err);
    });
moveFile(remotePath, targetPath)

Move a file or directory from remotePath to targetPath.

// Move a directory
client
    .moveFile("/some-dir", "/storage/moved-dir")
    .catch(function(err) {
        console.error(err);
    });

// Rename a file
client
    .moveFile("/images/pic.jpg", "/images/profile.jpg")
    .catch(function(err) {
        console.error(err);
    });
putFileContents(remotePath, format, data)

Put some data in a remote file at remotePath from a Buffer or String. format can be either "binary" or "text". data is a Buffer or a String.

var fs = require("fs");

var imageData = fs.readFileSync("someImage.jpg");

client
    .putFileContents("/folder/myImage.jpg", "binary", imageData)
    .catch(function(err) {
        console.error(err);
    });
client
    .putFileContents("/example.txt", "text", "some text")
    .catch(function(err) {
        console.error(err);
    });
stat(remotePath)

Get the stat properties of a remote file or directory at remotePath. Resolved object is a item stat object.

Returned data structures

Item stat

Item stats are objects with properties that descibe a file or directory. They resemble the following:

{
    "filename": "/test",
    "basename": "test",
    "lastmod": "Tue, 05 Apr 2016 14:39:18 GMT",
    "size": 0,
    "type": "directory"
}

or:

{
    "filename": "/image.jpg",
    "basename": "image.jpg",
    "lastmod": "Sun, 13 Mar 2016 04:23:32 GMT",
    "size": 42497,
    "type": "file",
    "mime": "image/jpeg"
}

Properties:

Property nameTypePresentDescription
filenameStringAlwaysFile path of the remote item
basenameStringAlwaysBase filename of the remote item, no path
lastmodStringAlwaysLast modification date of the item
sizeNumberAlwaysFile size - 0 for directories
typeStringAlwaysItem type - "file" or "directory"
mimeStringFiles onlyMime type - for file items only

Keywords

FAQs

Package last updated on 13 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc