Comparing version 12.0.3 to 12.1.0
26
index.js
@@ -6,3 +6,7 @@ import {readdir, stat, lstat} from "node:fs/promises"; | ||
const sepBuffer = Buffer.from(sep); | ||
const encoder = new TextEncoder(); | ||
const toUint8Array = encoder.encode.bind(encoder); | ||
const decoder = new TextDecoder(); | ||
const toString = decoder.decode.bind(decoder); | ||
const sepUint8Array = toUint8Array(sep); | ||
@@ -20,3 +24,3 @@ const defaults = { | ||
if (encoding === "buffer") { | ||
return dir === "." ? entry.name : Buffer.from([...dir, ...sepBuffer, ...entry.name]); | ||
return dir === "." ? entry.name : Uint8Array.from([...dir, ...sepUint8Array, ...entry.name]); | ||
} else { | ||
@@ -56,3 +60,3 @@ return dir === "." ? entry.name : `${dir}${sep}${entry.name}`; | ||
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1); | ||
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined; | ||
encoding = dir instanceof Uint8Array ? "buffer" : undefined; | ||
} | ||
@@ -71,6 +75,6 @@ | ||
const path = makePath(dirent, dir, encoding); | ||
if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue; | ||
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue; | ||
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink(); | ||
const encodedPath = encoding === "buffer" ? String(path) : path; | ||
const encodedPath = encoding === "buffer" ? toString(path) : path; | ||
const isIncluded = !includeMatcher || includeMatcher(encodedPath); | ||
@@ -109,3 +113,3 @@ let stats; | ||
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1); | ||
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined; | ||
encoding = dir instanceof Uint8Array ? "buffer" : undefined; | ||
} | ||
@@ -125,6 +129,6 @@ | ||
const path = makePath(dirent, dir, encoding); | ||
if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) return; | ||
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) return; | ||
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink(); | ||
const encodedPath = encoding === "buffer" ? String(path) : path; | ||
const encodedPath = encoding === "buffer" ? toString(path) : path; | ||
const isIncluded = !includeMatcher || includeMatcher(encodedPath); | ||
@@ -165,3 +169,3 @@ let stats; | ||
if (/[/\\]$/.test(dir)) dir = dir.substring(0, dir.length - 1); | ||
encoding = Buffer.isBuffer(dir) ? "buffer" : undefined; | ||
encoding = dir instanceof Uint8Array ? "buffer" : undefined; | ||
} | ||
@@ -181,6 +185,6 @@ | ||
const path = makePath(dirent, dir, encoding); | ||
if (excludeMatcher?.(encoding === "buffer" ? String(path) : path)) continue; | ||
if (excludeMatcher?.(encoding === "buffer" ? toString(path) : path)) continue; | ||
const isSymbolicLink = opts.followSymlinks && dirent.isSymbolicLink(); | ||
const encodedPath = encoding === "buffer" ? String(path) : path; | ||
const encodedPath = encoding === "buffer" ? toString(path) : path; | ||
const isIncluded = !includeMatcher || includeMatcher(encodedPath); | ||
@@ -187,0 +191,0 @@ let stats; |
{ | ||
"name": "rrdir", | ||
"version": "12.0.3", | ||
"version": "12.1.0", | ||
"description": "Recursive directory reader with a delightful API", | ||
@@ -5,0 +5,0 @@ "author": "silverwind <me@silverwind.io>", |
@@ -34,5 +34,5 @@ # rrdir | ||
#### `dir` *String* | *Buffer* | ||
#### `dir` *String* | *Uint8Array* | ||
The directory to read, either absolute or relative. Pass a `Buffer` to switch the module into `Buffer` mode which is required to be able to read every file, like for example files with names that are invalid UTF-8 sequences. | ||
The directory to read, either absolute or relative. Pass a `Uint8Array` to switch the module into `Uint8Array` mode which is required to be able to read every file, like for example files with names that are invalid UTF-8 sequences. | ||
@@ -50,3 +50,3 @@ #### `options` *Object* | ||
- `path` *string* | *Buffer*: The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Buffer`, this will be too. Always present. | ||
- `path` *string* | *Uint8Array*: The path to the entry, will be relative if `dir` is given relative. If `dir` is a `Uint8Array`, this will be too. Always present. | ||
- `directory` *boolean*: Boolean indicating whether the entry is a directory. `undefined` on error. | ||
@@ -53,0 +53,0 @@ - `symlink` *boolean*: Boolean indicating whether the entry is a symbolic link. `undefined` on error. |
10007
178