Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dat-ecosystem-archive/dat-glob
Glob implementation for dat archives [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
https://github.com/dat-ecosystem-archive/dat-glob
Last synced: 10 days ago
JSON representation
Glob implementation for dat archives [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
- Host: GitHub
- URL: https://github.com/dat-ecosystem-archive/dat-glob
- Owner: dat-ecosystem-archive
- License: apache-2.0
- Archived: true
- Created: 2018-11-21T15:53:32.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-28T20:55:51.000Z (almost 3 years ago)
- Last Synced: 2024-05-16T13:15:50.160Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - dat-glob - Glob implementation for dat archives (Using Dat / Dat Utilities)
README
[![deprecated](http://badges.github.io/stability-badges/dist/deprecated.svg)](https://dat-ecosystem.org/)
More info on active projects and modules at [dat-ecosystem.org](https://dat-ecosystem.org/)
---
# dat-glob
Glob implementation for `dat` archives.
Supports both raw `hyperdrive` instances and Beaker Browser's `DatArchive` API. With [`scoped-fs`](https://github.com/pfrazee/scoped-fs) you can use it on your local file system as well.
## Installation
In [Beaker](https://beakerbrowser.com) or [Webrun](https://github.com/RangerMauve/webrun) you can import the module directly in your code:
```js
import glob from 'dat://brecht.pamphlets.me/lib/dat-glob/v1.3.js'
```Note that it's advised to always use the `dat` protocol for this. HTTPS might be fine for testing, but I can't guarantee the required reliability and performance for production usage.
If you need `dat-glob` in Node.js, you can get it from NPM:
```sh
npm install dat-glob
```## Usage
This package exports two modules. The default `require('dat-glob')` works with async iteration, whereas `require('dat-glob/stream')` uses standard Node streams. Both modules include a `collect` method which returns a list of all matching files.
```js
// Async iteration
var glob = require('dat-glob')async function main () {
var dat = await DatArchive.create()for await (var file of glob(dat, '**/*.json')) {
console.log(file) // 'dat.json'
}var files = await glob(dat, '**/*.json').collect()
console.log(files) // ['dat.json']
}main()
// Node stream
var hyperdrive = require('hyperdrive')
var glob = require('dat-glob/stream')var dat = hyperdrive(key)
var stream = glob(dat, ['*.json', 'subdir/*.json'])stream.pipe(process.stdout)
stream.collect((err, files) => {
console.log(files)
})
```## API
### var results = glob(dat, pattern)
#### dat
Type: `object` (required)
A `DatArchive`, `hyperdrive`, or `scoped-fs` instance.
#### pattern
Type: `string` or `Array` (required)
A pattern (or list of patterns) to match against the files in the archive.
### var results = glob(dat, opts)
#### dat
See above.
#### opts.pattern
See above.
#### opts.base
Type: `string`
Subdirectory to start searching from.
#### opts.dir
Type: `boolean` (default: `false`)
Determines if `glob` matches directories as well as files.
### results.collect([callback])
Type: `function`
Returns `Promise` if no callback is passed in.
Collects all the files matched by the glob stream/iterator in an array.
## License
Apache-2.0