Skip to content

Commit

Permalink
fix: allow UInt8Array in pathToFilename
Browse files Browse the repository at this point in the history
This seems reasonable, considering memfs supports the browser,
and users are more likely to have instances of Uint8Array there.
  • Loading branch information
kylecarbs committed Dec 31, 2024
1 parent f389874 commit 1b72816
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('volume', () => {
throw Error('This should not throw');
} catch (err) {
expect(err).toBeInstanceOf(TypeError);
expect(err.message).toBe('path must be a string or Buffer');
expect(err.message).toBe('path must be a string, Buffer, or Uint8Array');
}
});
it('Invalid flags correct error code', () => {
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('volume', () => {
throw Error('This should not throw');
} catch (err) {
expect(err).toBeInstanceOf(TypeError);
expect(err.message).toBe('path must be a string or Buffer');
expect(err.message).toBe('path must be a string, Buffer, or Uint8Array');
done();
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/volume/__snapshots__/renameSync.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renameSync(fromPath, toPath) Throws if path is of wrong type 1`] = `"path must be a string or Buffer"`;
exports[`renameSync(fromPath, toPath) Throws if path is of wrong type 1`] = `"path must be a string, Buffer, or Uint8Array"`;

exports[`renameSync(fromPath, toPath) Throws on no params 1`] = `"path must be a string or Buffer"`;
exports[`renameSync(fromPath, toPath) Throws on no params 1`] = `"path must be a string, Buffer, or Uint8Array"`;

exports[`renameSync(fromPath, toPath) Throws on only one param 1`] = `"path must be a string or Buffer"`;
exports[`renameSync(fromPath, toPath) Throws on only one param 1`] = `"path must be a string, Buffer, or Uint8Array"`;
2 changes: 1 addition & 1 deletion src/node/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const enum MODE {
}

export const ERRSTR = {
PATH_STR: 'path must be a string or Buffer',
PATH_STR: 'path must be a string, Buffer, or Uint8Array',
// FD: 'file descriptor must be a unsigned 32-bit integer',
FD: 'fd must be a file descriptor',
MODE_INT: 'mode must be an int',
Expand Down
3 changes: 3 additions & 0 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ function getPathFromURLPosix(url): string {
}

export function pathToFilename(path: misc.PathLike): string {
if (path instanceof Uint8Array) {
path = bufferFrom(path);
}
if (typeof path !== 'string' && !Buffer.isBuffer(path)) {
try {
if (!(path instanceof require('url').URL)) throw new TypeError(ERRSTR.PATH_STR);
Expand Down

0 comments on commit 1b72816

Please sign in to comment.