Skip to content

Commit

Permalink
Merge pull request #29 from Picovoice/empty-remove-fix
Browse files Browse the repository at this point in the history
Fix missing check in remove and audit checks in seek
  • Loading branch information
ErisMik authored Nov 9, 2023
2 parents 028b7ec + 070a0db commit 65f30ce
Show file tree
Hide file tree
Showing 4 changed files with 1,195 additions and 1,041 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@picovoice/web-utils",
"version": "1.3.1",
"version": "1.3.2",
"description": "Picovoice web utility functions",
"author": "Picovoice",
"license": "Apache-2.0",
Expand Down
11 changes: 10 additions & 1 deletion src/pv_file_idb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Picovoice Inc.
Copyright 2022-2023 Picovoice Inc.
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
file accompanying this source.
Expand Down Expand Up @@ -271,6 +271,10 @@ export class PvFileIDB extends PvFile {
if (!this.exists() && this._mode === "readonly") {
throw new Error(`'${this._path}' doesn't exist.`);
}
if (!this.exists()) {
// This is valid in ISO C but not supported by this current implementation
throw new Error(`'${this._path}' doesn't exist.`);
}

if (offset < 0) {
const err = new Error(`EOF`);
Expand Down Expand Up @@ -309,6 +313,11 @@ export class PvFileIDB extends PvFile {
*/
public async remove(): Promise<void> {
return new Promise(async (resolve, reject) => {
if (!this.exists()) {
reject(new Error("ENOENT"));
return;
}

const numPages = this._meta!.numPages;
const keyRange = IDBKeyRange.bound(this._path, `${this._path}-${PvFileIDB.createPage(numPages)}`);
const store = this._store;
Expand Down
9 changes: 9 additions & 0 deletions src/pv_file_mem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ export class PvFileMem extends PvFile {
if (!this.exists() && this._mode === "readonly") {
throw new Error(`'${this._path}' doesn't exist.`);
}
if (!this.exists()) {
// This is valid in ISO C but not supported by this current implementation
throw new Error(`'${this._path}' doesn't exist.`);
}

if (offset < 0) {
const err = new Error(`EOF`);
err.name = "EndOfFile";
Expand Down Expand Up @@ -111,6 +116,10 @@ export class PvFileMem extends PvFile {
}

public async remove(): Promise<void> {
if (!this.exists()) {
throw new Error("ENOENT");
}

PvFileMem._memFiles.delete(this._path);
this._pos = 0;
}
Expand Down
Loading

0 comments on commit 65f30ce

Please sign in to comment.