Skip to content

Commit

Permalink
Optionally wait in readdir() and list()
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmturner committed Oct 3, 2024
1 parent b3246a2 commit af78a9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 = ''

Expand All @@ -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)
}
Expand Down

0 comments on commit af78a9e

Please sign in to comment.