Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

dat-ecosystem-archive/dat-rm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deprecated

More info on active projects and modules at 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 you can use it on your local file system as well.

Installation

In Beaker or Webrun you can import the module directly in your code:

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:

npm install dat-rm

Usage

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

About

Delete files from dat archives using glob patterns [ DEPRECATED - More info on active projects and modules at https://dat-ecosystem.org/ ]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published