chore(core): fix usage of Buffer

This commit is contained in:
Elian Doran
2026-03-27 16:45:44 +02:00
parent f069b41df6
commit 55f09fe21a
2 changed files with 7 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ interface ImportZipOpts {
preserveIds?: boolean;
}
async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Buffer, importRootNote: BNote, opts?: ImportZipOpts): Promise<BNote> {
async function importZip(taskContext: TaskContext<"importNotes">, fileBuffer: Uint8Array, importRootNote: BNote, opts?: ImportZipOpts): Promise<BNote> {
/** maps from original noteId (in ZIP file) to newly generated noteId */
const noteIdMap: Record<string, string> = {};
/** type maps from original attachmentId (in ZIP file) to newly generated attachmentId */
@@ -655,9 +655,9 @@ export function readContent(zipfile: yauzl.ZipFile, entry: yauzl.Entry): Promise
});
}
export function readZipFile(buffer: Buffer, processEntryCallback: (zipfile: yauzl.ZipFile, entry: yauzl.Entry) => Promise<void>) {
export function readZipFile(buffer: Uint8Array, processEntryCallback: (zipfile: yauzl.ZipFile, entry: yauzl.Entry) => Promise<void>) {
return new Promise<void>((res, rej) => {
yauzl.fromBuffer(buffer, { lazyEntries: true, validateEntrySizes: false }, (err, zipfile) => {
yauzl.fromBuffer(Buffer.from(buffer), { lazyEntries: true, validateEntrySizes: false }, (err, zipfile) => {
if (err) rej(err);
if (!zipfile) throw new Error("Unable to read zip file.");

View File

@@ -73,21 +73,21 @@ export function wrapStringOrBuffer(stringOrBuffer: string | Uint8Array) {
* @param data the string or buffer to process.
* @returns the string representation of the buffer, or the same string is it's a string.
*/
export function processStringOrBuffer(data: string | Buffer | null) {
export function processStringOrBuffer(data: string | Uint8Array | null) {
if (!data) {
return "";
}
if (!Buffer.isBuffer(data)) {
if (typeof data === "string") {
return data;
}
const detectedEncoding = chardet.detect(data);
switch (detectedEncoding) {
case "UTF-16LE":
return stripBom(data.toString("utf-16le"));
return stripBom(new TextDecoder("utf-16le").decode(data));
case "UTF-8":
default:
return data.toString("utf-8");
return utf8Decoder.decode(data);
}
}