Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions frame/recoverable.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,19 @@ module.exports = function (blocks, blockSize, offsetCodec) {
/**
* Overwrites an item at `offset` with null bytes.
*
* The only bytes we need to change are the actual data bytes, so we can skip
* the book-end bytes that record the length of the data and *only* touch the
* data bytes themselves.
*
* @param {number} offset - the offset of the item to overwrite
* @param {function} cb - callback that returns any error as an argument
*/
const overwrite = (offset, cb) => {
blocks.readUInt32BE(offset, function (err, len) {
if (err) return cb(err)

const bookend = Buffer.alloc(4)
bookend.writeUInt32BE(len, 0)

const nullBytes = Buffer.alloc(len)
const full = Buffer.concat([bookend, nullBytes, bookend])

blocks.write(full, offset, cb)
blocks.write(nullBytes, offset + 4, cb)
})
}

Expand Down