Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dat-ecosystem-archive/dat-rm
Delete files from dat archives using glob patterns [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
https://github.com/dat-ecosystem-archive/dat-rm
Last synced: 10 days ago
JSON representation
Delete files from dat archives using glob patterns [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]
- Host: GitHub
- URL: https://github.com/dat-ecosystem-archive/dat-rm
- Owner: dat-ecosystem-archive
- License: apache-2.0
- Archived: true
- Created: 2018-11-21T20:43:36.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-28T20:54:08.000Z (almost 3 years ago)
- Last Synced: 2024-05-16T13:15:59.766Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-dat - dat-rm - Rimraf equivalent 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-rm
Delete files from `dat` archives using glob patterns.
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 rm from 'dat://brecht.pamphlets.me/lib/dat-rm/v1.1.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-rm` in Node.js, you can get it from NPM:
```sh
npm install dat-rm
```## Usage
```js
var rm = require('dat-rm')async function main () {
var dat = await DatArchive.load(key)// delete all Markdown files in the archive
await rm(dat, '**/*.md')
// delete all jpg images and prune any directories left empty
await rm(dat, '**/*.jpg', { prune: true })
// delete entire subdirectory, including its contents
await rm(dat, 'subdir')
}main()
// Instead of using `await`, you can pass in a callback too
var hyperdrive = require('hyperdrive')
var rm = require('dat-rm')var dat = hyperdrive(key)
rm(dat, 'subdir', function (err) {
if (err) console.error(err)
else console.info('done!')
})
```## API
### rm(dat, pattern [, opts, callback])
#### dat
Type: `object` (required)
A `DatArchive`, `hyperdrive`, or `scoped-fs` instance.
#### pattern
Type: `string` or `Array` (required)
A glob (or list of globs) that describes the files to be removed from the archive.
#### opts.prune
Type: `boolean` (default: `false`)
Determines whether empty directories should be removed as well.
#### callback
Type `function`
Optional callback argument. If not provided, `rm` will return a promise.
## License
Apache-2.0