Skip to content

Commit

Permalink
implement exists (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapaezbas authored Jan 31, 2025
1 parent 97503be commit b3ca96c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ module.exports = class Localdrive {
}
}

async exists (name) {
return await this.entry(name) !== null
}

mirror (out, opts) {
return new MirrorDrive(this, out, opts)
}
Expand Down
10 changes: 10 additions & 0 deletions test/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,13 @@ test('non-existing follow entry', async function (t) {

t.is(await drive.entry('/file.random.shortcut', { follow: true }), null)
})

test('exists', async function (t) {
const drive = createDrive(t)
t.is(await drive.exists('/examples/a.txt'), true)
t.is(await drive.exists('/exists.txt'), false)

await drive.put('/exists.txt', Buffer.from('hello-world'))

t.is(await drive.exists('/exists.txt'), true)
})

0 comments on commit b3ca96c

Please sign in to comment.