Skip to content

Commit 65f30ce

Browse files
authored
Merge pull request #29 from Picovoice/empty-remove-fix
Fix missing check in remove and audit checks in seek
2 parents 028b7ec + 070a0db commit 65f30ce

File tree

4 files changed

+1195
-1041
lines changed

4 files changed

+1195
-1041
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@picovoice/web-utils",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Picovoice web utility functions",
55
"author": "Picovoice",
66
"license": "Apache-2.0",

src/pv_file_idb.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2022 Picovoice Inc.
2+
Copyright 2022-2023 Picovoice Inc.
33
44
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
55
file accompanying this source.
@@ -271,6 +271,10 @@ export class PvFileIDB extends PvFile {
271271
if (!this.exists() && this._mode === "readonly") {
272272
throw new Error(`'${this._path}' doesn't exist.`);
273273
}
274+
if (!this.exists()) {
275+
// This is valid in ISO C but not supported by this current implementation
276+
throw new Error(`'${this._path}' doesn't exist.`);
277+
}
274278

275279
if (offset < 0) {
276280
const err = new Error(`EOF`);
@@ -309,6 +313,11 @@ export class PvFileIDB extends PvFile {
309313
*/
310314
public async remove(): Promise<void> {
311315
return new Promise(async (resolve, reject) => {
316+
if (!this.exists()) {
317+
reject(new Error("ENOENT"));
318+
return;
319+
}
320+
312321
const numPages = this._meta!.numPages;
313322
const keyRange = IDBKeyRange.bound(this._path, `${this._path}-${PvFileIDB.createPage(numPages)}`);
314323
const store = this._store;

src/pv_file_mem.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ export class PvFileMem extends PvFile {
8383
if (!this.exists() && this._mode === "readonly") {
8484
throw new Error(`'${this._path}' doesn't exist.`);
8585
}
86+
if (!this.exists()) {
87+
// This is valid in ISO C but not supported by this current implementation
88+
throw new Error(`'${this._path}' doesn't exist.`);
89+
}
90+
8691
if (offset < 0) {
8792
const err = new Error(`EOF`);
8893
err.name = "EndOfFile";
@@ -111,6 +116,10 @@ export class PvFileMem extends PvFile {
111116
}
112117

113118
public async remove(): Promise<void> {
119+
if (!this.exists()) {
120+
throw new Error("ENOENT");
121+
}
122+
114123
PvFileMem._memFiles.delete(this._path);
115124
this._pos = 0;
116125
}

0 commit comments

Comments
 (0)