Skip to content

Commit

Permalink
Merge pull request #106 from tusharmath/override-meta-params
Browse files Browse the repository at this point in the history
feat(DownloadFromMTDFile): add support for overriding meta that is be…
  • Loading branch information
tusharmath committed Jul 9, 2016
2 parents 445c429 + 407e6da commit 414e04c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $ mtd --help
## Functions

* [CreateMTDFile(options)](#CreateMTDFile) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
* [DownloadFromMTDFile(mtdPath)](#DownloadFromMTDFile) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
* [DownloadFromMTDFile(mtdPath, [meta])](#DownloadFromMTDFile) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
* [FinalizeDownload(params)](#FinalizeDownload) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
* [Completion(meta$)](#Completion) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>

Expand Down Expand Up @@ -187,7 +187,7 @@ information regarding the download appended to the end.

<a name="DownloadFromMTDFile"></a>

## DownloadFromMTDFile(mtdPath) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
## DownloadFromMTDFile(mtdPath, [meta]) ⇒ <code>[Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)</code>
Reads a `.mtd` file and resumes the download from the last successfully saved
byte.

Expand All @@ -203,6 +203,7 @@ byte.
| Param | Type | Description |
| --- | --- | --- |
| mtdPath | <code>String</code> | Relative path to the `.mtd` file. |
| [meta] | <code>Object</code> | Optional meta data to override the one that's being loaded from the `.mtd` file. |

<a name="FinalizeDownload"></a>

Expand Down
5 changes: 4 additions & 1 deletion src/DownloadFromMTDFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
* byte.
* @function
* @param {String} mtdPath - Relative path to the `.mtd` file.
* @param {Object} [meta] - Optional meta data to override the one that's being
* loaded from the `.mtd` file.
* @return {external:Observable}
* A {@link https://github.com/tusharmath/muxer multiplexed stream} containing ~
* - `metaWritten$` - Meta data buffer stream.
Expand All @@ -36,7 +38,7 @@ import {
* - `fdR$` - File Descriptor in `r+` mode.
* - `meta$` - Download meta information.
*/
export const DownloadFromMTDFile = R.curry(({FILE, HTTP}, mtdPath) => {
export const DownloadFromMTDFile = R.curryN(2, ({FILE, HTTP}, mtdPath, _meta) => {
/**
* Open file to read+append
*/
Expand All @@ -52,6 +54,7 @@ export const DownloadFromMTDFile = R.curry(({FILE, HTTP}, mtdPath) => {
*/
const metaPosition$ = MetaPosition$({size$})
const meta$ = ReadJSON$({FILE, fd$, position$: metaPosition$})
.map(meta => R.merge(meta, _meta))

/**
* Make a HTTP request for each thread
Expand Down
15 changes: 15 additions & 0 deletions test/test.DownloadFromMTDFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,18 @@ test('requestCount', t => {
sh.startScheduler(() => DownloadFromMTDFile(params, './home/file.mtd'))
t.is(params.HTTP.request.callCount, 3)
})

test('override meta data', t => {
const sh = new TestScheduler()
const params = createParams(sh, {
url: '/a/b/c',
threads: [[0, 10]],
offsets: [5]
})
sh.startScheduler(() => DownloadFromMTDFile(params, './home/file.mtd', {url: '/p/q/r'}))
t.is(params.HTTP.request.callCount, 1)
t.true(params.HTTP.request.calledWith({
url: '/p/q/r',
headers: {range: 'bytes=5-10'}
}))
})

0 comments on commit 414e04c

Please sign in to comment.