<commit_before>![WebDAV](https://raw.githubusercontent.com/perry-mitchell/webdav-client/master/webdav.jpg)

> A WebDAV client written in JavaScript for NodeJS and the browser.

[![Build Status](https://travis-ci.org/perry-mitchell/webdav-client.svg?branch=master)](https://travis-ci.org/perry-mitchell/webdav-client) [![npm version](https://badge.fury.io/js/webdav.svg)](https://www.npmjs.com/package/webdav) [![monthly downloads](https://img.shields.io/npm/dm/webdav.svg)](https://www.npmjs.com/package/webdav)

## About
This client was branched from [webdav-fs](https://github.com/perry-mitchell/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. This client uses `window.fetch` when available in the browser.

Please read our [contribution guide](CONTRIBUTING.md) if you plan on making an issue or PR.

## Installation
To install for use with NodeJS, execute the following shell command:

```shell
npm install webdav --save
```

## Usage
Usage is very simple ([API](API.md)) - the main exported object is a factory to create adapter instances:

```js
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));
    });
```

Each method returns a `Promise`.

### Authentication
`webdav` uses `Basic` authentication by default, if `username` and `password` are provided (if none are provided, no `Authorization` header is specified). It also supports OAuth tokens - simply pass the token data to the `username` field:

```javascript
createClient(
    "https://address.com",
    {
        "access_token": "<KEY>",
        "token_type": "example",
        "expires_in": 3600,
        "refresh_token": "<PASSWORD>",
        "example_parameter": "example_value"
    }
);
```

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

#### copyFile(remotePath, targetPath _[, options]_)
Copy a file or directory from one path to another.

#### createDirectory(remotePath _[, options]_)
Create a new directory at the remote path.

#### createReadStream(remotePath _[, options]_)
Creates a readable stream on the remote path.

Returns a readable stream instance.

##### options.range
Optionally request part of the remote file by specifying the `start` and `end` byte positions. The `end` byte position is optional and the rest of the file from `start` onwards will be streamed.

```javascript
var stream = client.createReadStream("/test/image.png", {
    range: { start: 0, end: 499 } // first 500 bytes
});
```

#### createWriteStream(remotePath _[, options]_)
Creates a writeable stream to a remote path.

Returns a writeable stream instance.
<commit_msg>Mention PassThroughStream usage for createWriteStream<commit_after>![WebDAV](https://raw.githubusercontent.com/perry-mitchell/webdav-client/master/webdav.jpg)

> A WebDAV client written in JavaScript for NodeJS and the browser.

[![Build Status](https://travis-ci.org/perry-mitchell/webdav-client.svg?branch=master)](https://travis-ci.org/perry-mitchell/webdav-client) [![npm version](https://badge.fury.io/js/webdav.svg)](https://www.npmjs.com/package/webdav) [![monthly downloads](https://img.shields.io/npm/dm/webdav.svg)](https://www.npmjs.com/package/webdav)

## About
This client was branched from [webdav-fs](https://github.com/perry-mitchell/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. This client uses `window.fetch` when available in the browser.

Please read our [contribution guide](CONTRIBUTING.md) if you plan on making an issue or PR.

## Installation
To install for use with NodeJS, execute the following shell command:

```shell
npm install webdav --save
```

## Usage
Usage is very simple ([API](API.md)) - the main exported object is a factory to create adapter instances:

```js
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));
    });
```

Each method returns a `Promise`.

### Authentication
`webdav` uses `Basic` authentication by default, if `username` and `password` are provided (if none are provided, no `Authorization` header is specified). It also supports OAuth tokens - simply pass the token data to the `username` field:

```javascript
createClient(
    "https://address.com",
    {
        "access_token": "<KEY>",
        "token_type": "example",
        "expires_in": 3600,
        "refresh_token": "<PASSWORD>",
        "example_parameter": "example_value"
    }
);
```

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

#### copyFile(remotePath, targetPath _[, options]_)
Copy a file or directory from one path to another.

#### createDirectory(remotePath _[, options]_)
Create a new directory at the remote path.

#### createReadStream(remotePath _[, options]_)
Creates a readable stream on the remote path.

Returns a readable stream instance.

##### options.range
Optionally request part of the remote file by specifying the `start` and `end` byte positions. The `end` byte position is optional and the rest of the file from `start` onwards will be streamed.

```javascript
var stream = client.createReadStream("/test/image.png", {
    range: { start: 0, end: 499 } // first 500 bytes
});
```

#### createWriteStream(remotePath _[, options]_)
Creates a writeable stream to a remote path.

Returns a writeable stream instance. Note that the actual stream returned is a [Node `PassThroughStream`](PassThroughStream) instance, not a `stream.Writable`.

{'fraction_non_alphanumeric': 0.12267303102625299, 'fraction_numerical': 0.0038186157517899762, 'mean_word_length': 4.433016421780467, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 20, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '437316', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1775, 'n_words': 640}