Comparing version 0.8.0 to 0.9.0
28
API.md
@@ -41,5 +41,7 @@ ## Functions | ||
* [.createDirectory(dirPath, [options])](#ClientInterface.createDirectory) ⇒ <code>Promise</code> | ||
* [.createReadStream(remoteFilename, [options])](#ClientInterface.createReadStream) ⇒ <code>Readable</code> | ||
* [.deleteFile(remotePath, [options])](#ClientInterface.deleteFile) ⇒ <code>Promise</code> | ||
* [.getDirectoryContents(remotePath, [options])](#ClientInterface.getDirectoryContents) ⇒ <code>Promise.<Array></code> | ||
* [.getFileContents(remoteFilename, [options])](#ClientInterface.getFileContents) ⇒ <code>Promise.<(Buffer\|String)></code> | ||
* [.getFileStream(remoteFilename, [options])](#ClientInterface.getFileStream) ⇒ <code>Promise.<Readable></code> | ||
* [.moveFile(remotePath, targetRemotePath, [options])](#ClientInterface.moveFile) ⇒ <code>Promise</code> | ||
@@ -62,2 +64,15 @@ * [.putFileContents(remoteFilename, data, [options])](#ClientInterface.putFileContents) ⇒ <code>Promise</code> | ||
<a name="ClientInterface.createReadStream"></a> | ||
### ClientInterface.createReadStream(remoteFilename, [options]) ⇒ <code>Readable</code> | ||
Create a readable stream of a remote file | ||
**Kind**: static method of <code>[ClientInterface](#ClientInterface)</code> | ||
**Returns**: <code>Readable</code> - A readable stream | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| remoteFilename | <code>String</code> | The file to stream | | ||
| [options] | <code>[OptionsHeadersAndFormat](#OptionsHeadersAndFormat)</code> | Options for the request | | ||
<a name="ClientInterface.deleteFile"></a> | ||
@@ -102,2 +117,15 @@ | ||
<a name="ClientInterface.getFileStream"></a> | ||
### ClientInterface.getFileStream(remoteFilename, [options]) ⇒ <code>Promise.<Readable></code> | ||
Get a readable stream of a remote file | ||
**Kind**: static method of <code>[ClientInterface](#ClientInterface)</code> | ||
**Returns**: <code>Promise.<Readable></code> - A promise that resolves with a readable stream | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| remoteFilename | <code>String</code> | The file to stream | | ||
| [options] | <code>[OptionsHeadersAndFormat](#OptionsHeadersAndFormat)</code> | Options for the request | | ||
<a name="ClientInterface.moveFile"></a> | ||
@@ -104,0 +132,0 @@ |
# WebDAV-client changelog | ||
## 0.9.0 | ||
_2017-06-07_ | ||
* Add support for ranges with only `start` | ||
## 0.8.0 | ||
@@ -4,0 +9,0 @@ _2017-06-07_ |
{ | ||
"name": "webdav", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "WebDAV client for NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "source/index.js", |
@@ -108,3 +108,3 @@ # WebDAV client | ||
##### options.range | ||
Optionally request part of the remote file by specifying the `start` and `end` byte positions. | ||
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. | ||
@@ -111,0 +111,0 @@ ```javascript |
@@ -77,5 +77,8 @@ var xml2js = require("xml2js"), | ||
options = deepmerge({ headers: {} }, options || {}); | ||
if (typeof options.range === "object") { | ||
options.headers.Range = "bytes=" + options.range.start + "-" + | ||
options.range.end; | ||
if (typeof options.range === "object" && typeof options.range.start === "number") { | ||
var rangeHeader = "bytes=" + options.range.start + "-"; | ||
if (typeof options.range.end === "number") { | ||
rangeHeader += options.range.end; | ||
} | ||
options.headers.Range = rangeHeader; | ||
} | ||
@@ -82,0 +85,0 @@ return fetch(url + filePath, { |
@@ -22,2 +22,12 @@ var path = require("path"); | ||
function streamToBuffer(stream) { | ||
var buffs = []; | ||
return new Promise(function(resolve) { | ||
stream.on("data", function(d) { buffs.push(d); }); | ||
stream.on("end", function() { | ||
resolve(Buffer.concat(buffs)); | ||
}); | ||
}); | ||
} | ||
describe("adapter:get", function() { | ||
@@ -135,9 +145,3 @@ | ||
expect(stream instanceof ReadableStream).to.be.true; | ||
var buffers = []; | ||
return new Promise(function(resolve) { | ||
stream.on("data", function(d) { buffers.push(d); }); | ||
stream.on('end', function() { | ||
resolve(Buffer.concat(buffers)); | ||
}); | ||
}); | ||
return streamToBuffer(stream); | ||
}) | ||
@@ -158,17 +162,5 @@ .then(function(buff) { | ||
part2 = streams.shift(); | ||
var part1Buffers = [], | ||
part2Buffers = []; | ||
return Promise.all([ | ||
new Promise(function(resolve) { | ||
part1.on("data", function(d) { part1Buffers.push(d); }); | ||
part1.on('end', function() { | ||
resolve(Buffer.concat(part1Buffers)); | ||
}); | ||
}), | ||
new Promise(function(resolve) { | ||
part2.on("data", function(d) { part2Buffers.push(d); }); | ||
part2.on('end', function() { | ||
resolve(Buffer.concat(part2Buffers)); | ||
}); | ||
}) | ||
streamToBuffer(part1), | ||
streamToBuffer(part2) | ||
]); | ||
@@ -184,2 +176,13 @@ }) | ||
it("streams a partial file when only start is provided", function() { | ||
return getAdapter | ||
.getFileStream(SERVER_URL, "/gem.png", { range: { start: 200 } }) | ||
.then(function(stream) { | ||
return streamToBuffer(stream); | ||
}) | ||
.then(function(buff) { | ||
expect(buff.length).to.equal(79); | ||
}); | ||
}); | ||
}); | ||
@@ -186,0 +189,0 @@ |
58656
1006