diff --git a/README.md b/README.md
index f083b5f..15e1f3e 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ $ mtd --help
## Functions
* [CreateMTDFile(options)](#CreateMTDFile) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
-* [DownloadFromMTDFile(mtdPath)](#DownloadFromMTDFile) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
+* [DownloadFromMTDFile(mtdPath, [meta])](#DownloadFromMTDFile) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
* [FinalizeDownload(params)](#FinalizeDownload) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
* [Completion(meta$)](#Completion) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
@@ -187,7 +187,7 @@ information regarding the download appended to the end.
-## DownloadFromMTDFile(mtdPath) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
+## DownloadFromMTDFile(mtdPath, [meta]) ⇒ [Observable](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/observable.md)
Reads a `.mtd` file and resumes the download from the last successfully saved
byte.
@@ -203,6 +203,7 @@ byte.
| Param | Type | Description |
| --- | --- | --- |
| mtdPath | String
| Relative path to the `.mtd` file. |
+| [meta] | Object
| Optional meta data to override the one that's being loaded from the `.mtd` file. |
diff --git a/src/DownloadFromMTDFile.js b/src/DownloadFromMTDFile.js
index cc44eb5..7c588ef 100644
--- a/src/DownloadFromMTDFile.js
+++ b/src/DownloadFromMTDFile.js
@@ -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.
@@ -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
*/
@@ -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
diff --git a/test/test.DownloadFromMTDFile.js b/test/test.DownloadFromMTDFile.js
index 9e83d00..c2f195f 100644
--- a/test/test.DownloadFromMTDFile.js
+++ b/test/test.DownloadFromMTDFile.js
@@ -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'}
+ }))
+})