diff --git a/README.md b/README.md index 8b6762d..c5c91c5 100644 --- a/README.md +++ b/README.md @@ -226,14 +226,22 @@ Returns a stream of all entries in the drive at paths prefixed with `folder`. ```js { recursive: true | false // Whether to descend into all subfolders or not, - ignore: String || Array // Ignore files and folders by name. + ignore: String || Array // Ignore files and folders by name, + wait: true, // Wait for block to be downloaded. } ``` -#### `const stream = drive.readdir(folder)` +#### `const stream = drive.readdir(folder, [options])` Returns a stream of all subpaths of entries in drive stored at paths prefixed by `folder`. +`options` include: +```js +{ + wait: true, // Wait for block to be downloaded +} +``` + #### `const stream = await drive.entries([range], [options])` Returns a read stream of entries in the drive. diff --git a/index.js b/index.js index 54be5a1..5868eb5 100644 --- a/index.js +++ b/index.js @@ -478,13 +478,13 @@ module.exports = class Hyperdrive extends ReadyResource { folder = std(folder || '/', true) const ignore = opts.ignore ? normalizeIgnore(opts.ignore) : null - const stream = opts && opts.recursive === false ? shallowReadStream(this.db, folder, false, ignore) : this.entries(prefixRange(folder), { ignore }) + const stream = opts && opts.recursive === false ? shallowReadStream(this.db, folder, false, ignore, opts) : this.entries(prefixRange(folder), { ignore, ...opts }) return stream } - readdir (folder) { + readdir (folder, opts) { folder = std(folder || '/', true) - return shallowReadStream(this.db, folder, true, null) + return shallowReadStream(this.db, folder, true, null, opts) } mirror (out, opts) { @@ -622,7 +622,7 @@ module.exports = class Hyperdrive extends ReadyResource { } } -function shallowReadStream (files, folder, keys, ignore) { +function shallowReadStream (files, folder, keys, ignore, opts) { let prev = '/' let prevName = '' @@ -631,7 +631,7 @@ function shallowReadStream (files, folder, keys, ignore) { let node = null try { - node = await files.peek(prefixRange(folder, prev), { keyEncoding }) + node = await files.peek(prefixRange(folder, prev), { keyEncoding, ...opts }) } catch (err) { return cb(err) }