holepunchto / hyperdrive

Hyperdrive is a secure, real time distributed file system
Apache License 2.0
1.85k stars 136 forks source link

Add `rename` method #364

Open RangerMauve opened 6 months ago

RangerMauve commented 6 months ago

It'd be useful to have an easy way to move entries to new locations. At the moment one needs to either duplicate data and delete the old data in a batch, or mess with internal APIs.

I propose something like this:

async rename(src, dst) {
  const entry = await this.entry(src)
  const batch = this.db.batch()
  batch.del(src)
  batch.put(dst, entry)
  batch.flush()
}

Would a PR that adds a working method as well as unit tests work for y'all?