Open digable1 opened 11 months ago
Don’t think I’ll have a chance to look at this today but I’m guessing your trying to use the library in Node.js right?The library was designed to utilise browser APIs such as Worker and Blob. It could probably be adapted to work without, but it will take a bit of work.Sent from my iPhoneOn 23 Sep 2023, at 01:05, digable1 @.> wrote:
First off: I would not be surprised if this was 'operator error'. I just don't know why, as so far I think I'm doing it right (famous last words)...
I'm getting the following error message:
ReferenceError: Worker is not defined
at create_worker @.\webzip\index.js:747:20)
at get_worker @.\webzip\index.js:757:25)
at @.\webzip\index.js:773:24
at new Promise (
demo.ts: import { ZipArchive } from @.***/webzip";
enum ZipentryType { string, blob, arrayBuffer }
async function getZipFile(zipFile: string, zipContents: ZipArchive, output = ZipentryType.string): Promise<string | Blob | undefined> {
console.log(getZipFile - zipFile: ${zipFile}
);
const zipEntry = zipContents.get(zipFile);
if (zipEntry) {
try {
if (output === ZipentryType.string) {
return await zipEntry.get_string()
}
} catch(e) {
console.error(Could not get the contents of zip file '${zipFile}' in archive
);
console.error();
console.log(Zip Entry: ${JSON.stringify(zipEntry, null, 4)}
);
console.error();
console.error(Directory file names (just to prove it really is a blob zip): ${getZipDirectory(zipContents).join("\n ")}
);
console.error();
console.error(Error:
)
console.error(e);
}
}
return new Promise((resolve) => resolve(undefined));
function getZipDirectory(zipContentsParm: ZipArchive): Array<string> {
const directoryNames: Array<string> = [];
const directoryIterator = zipContentsParm.files();
let next = directoryIterator.next();
while (next && next.done !== undefined && !next.done) {
directoryNames.push(next.value[0]);
next = directoryIterator.next();
}
return directoryNames;
}
}
async function main(): PromiseFetching url '${fccDataUrl}' - be patient...
)
const fccRespone = await fetch(fccDataUrl);
const blobContents = await fccRespone.blob();
const archive = await ZipArchive.from_blob(blobContents);
await getZipFile('EN.dat', archive);
}
main().then(
() => console.log(Done
)
)
tsconfig.json:
{
"compilerOptions": {
"target": "ESNext",
"allowJs": false,
"skipLibCheck": false,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "ESNext",
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true,
},
"ts-node": {
"esm": true,
"compilerOptions": {
"module": "nodenext"
}
}
}
Invoked by: npx ts-node --project tools/tsconfig.json tools/demo.ts
Anybody know what's up?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
Yup - using node ('Invoked by: npx ts-node --project tools/tsconfig.json tools/demo.ts'). Didn't see that callout anywhere in the doc.
Might help to call this out, short-term. Even better short-term would also be a quick check at startup and stop if node is identified - with a helpful error message.
However: Longer term, would appreciate the ability for Node to support this as well. I like that this is in TypeScript and the ZipArchive.from_blob(
My WIP overhaul should work in Node and the browser 😄 Node has moved on a bit and it has some the browser standard parts available in the global scope now. As well as support for Compression/Decompression stream.
Still got a bit of work to do but it's looking promising. I'll keep this issue open as a tracker for an isomorphic build
First off: I would not be surprised if this was 'operator error'. I just don't know why, as so far I think I'm doing it right (famous last words)...
I'm getting the following error message:
demo.ts:
tsconfig.json:
Invoked by: npx ts-node --project tools/tsconfig.json tools/demo.ts
Anybody know what's up?