Skip to content

Isomorphic build #6

@digable1

Description

@digable1

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 (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:747:20)
    at get_worker (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:757:25)
    at c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:773:24
    at new Promise (<anonymous>)
    at decompress (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:772:12)
    at decompress$1 (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:40:12)
    at ZipEntry.decompress (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:124:34)
    at ZipEntry.get_blob (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:208:25)
    at ZipEntry.get_string (c:\projects\qso-logbook-next\node_modules\@shortercode\webzip\index.js:218:33)
    at getZipFile (c:\projects\qso-logbook-next\tools\demo.ts:15:39)

demo.ts:

import { ZipArchive } from "@shortercode/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(): Promise<void> {
    const fccDataUrl = 'https://data.fcc.gov/download/pub/uls/complete/l_amat.zip';
    console.log(`Fetching 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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions