Skip to content

Commit

Permalink
Lint, npmignore
Browse files Browse the repository at this point in the history
  • Loading branch information
nika-begiashvili committed Jan 23, 2024
1 parent 44a613c commit 81fff4b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 74 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "master" ]
branches: ["master"]
pull_request:
branches: [ "master" ]
branches: ["master"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,12 +19,12 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test
lib
1 change: 0 additions & 1 deletion main.js

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "libarchive.js",
"version": "2.0.0",
"description": "extract archive files in browser, libarchive port in wasm",
"main": "main.js",
"description": "extract/create archive files in browser/nodejs, libarchive port in wasm",
"main": "dist/libarchive.js",
"repository": {
"type": "git",
"url": "https://github.com/nika-begiashvili/libarchivejs"
Expand All @@ -24,7 +24,8 @@
"7z",
"javascript",
"js",
"browser"
"browser",
"nodejs"
],
"author": "Nika Begiashvili",
"license": "MIT",
Expand Down
81 changes: 39 additions & 42 deletions src/archive-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,56 @@ import { CompressedFile } from "./compressed-file.js";
import { cloneContent, getObjectPropReference, objectToArray } from "./utils";

export type ArchiveEntry = {
size: number;
path: string;
type: string;
lastModified: number;
fileData: ArrayBuffer;
fileName: string;
};
size: number;
path: string;
type: string;
lastModified: number;
fileData: ArrayBuffer;
fileName: string;
};

export class ArchiveReader {
private file: File | null;
private client: any;
private worker: any;

private file: File | null;
private client: any;
private worker: any;
private _content: any = {};
private _processed: number = 0;

private _content: any = {};
private _processed: number = 0;

constructor(file: File, client: any, worker: any) {
this.file = file;
this.client = client;
this.worker = worker;
}
constructor(file: File, client: any, worker: any) {
this.file = file;
this.client = client;
this.worker = worker;
}

/**
/**
* Prepares file for reading
* @returns {Promise<Archive>} archive instance
*/
open(): Promise<ArchiveReader> {
this._content = {};
this._processed = 0;
return new Promise((resolve, _) => {
this.client.open(
this.file,
Comlink.proxy(() => {
resolve(this);
}),
);
});
}
open(): Promise<ArchiveReader> {
this._content = {};
this._processed = 0;
return new Promise((resolve, _) => {
this.client.open(
this.file,
Comlink.proxy(() => {
resolve(this);
}),
);
});
}

/**
/**
* Terminate worker to free up memory
*/
async close() {
this.worker?.terminate();
this.worker = null;
this.client = null;
this.file = null;
}
async close() {
this.worker?.terminate();
this.worker = null;
this.client = null;
this.file = null;
}

/**
/**
* detect if archive has encrypted data
* @returns {boolean|null} null if could not be determined
*/
Expand Down Expand Up @@ -155,6 +154,4 @@ export class ArchiveReader {
this.worker?.terminate();
return cloneContent(this._content);
}


}
}
4 changes: 2 additions & 2 deletions src/libarchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ export class Archive {
}

private static async getClient(worker: any, options: ArchiveOptions) {
const Client = options.createClient?.(worker) || (Comlink.wrap(worker as any) as any);
const Client =
options.createClient?.(worker) || (Comlink.wrap(worker as any) as any);

// @ts-ignore - Promise.WithResolvers
let { promise: clientReady, resolve } = Promise.withResolvers();
Expand All @@ -95,5 +96,4 @@ export class Archive {

return client;
}

}
4 changes: 2 additions & 2 deletions src/webworker/archive-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ export class ArchiveWriter {

readNumberFromPointer(ptr) {
const ptrSize = this._runCode.sizeOfSizeT();
const outputSizeBytes = this._wasmModule.HEAPU8.slice(ptr,ptr + ptrSize);
const outputSizeBytes = this._wasmModule.HEAPU8.slice(ptr, ptr + ptrSize);

let output = null;
if (ptrSize == 4) {
output = new Uint32Array(outputSizeBytes)[0];
} else if (ptrSize == 8) {
output = new BigUint64Array(outputSizeBytes)[0];
} else throw Error("Unexpected size of size_t: " + ptrSize);

return output;
}
}
18 changes: 11 additions & 7 deletions test/node.test.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Archive, ArchiveCompression, ArchiveFormat } from "../dist/libarchive-node.mjs";
import {
Archive,
ArchiveCompression,
ArchiveFormat,
} from "../dist/libarchive-node.mjs";
import fs from "fs";
import { Blob } from "buffer";
import { fileChecksums } from "./checksum-utils";
Expand All @@ -17,16 +21,17 @@ describe("Extract file using nodejs", () => {
archive.close();
}, 5000);


test("Create new archive", async () => {
let buffer = fs.readFileSync("test/files/archives/README.md");
let blob = new Blob([buffer]);

const archiveFile = await Archive.write({
files: [{
file: blob,
pathname: "README.md",
}],
files: [
{
file: blob,
pathname: "README.md",
},
],
outputFileName: "test.tar.gz",
compression: ArchiveCompression.GZIP,
format: ArchiveFormat.USTAR,
Expand All @@ -40,5 +45,4 @@ describe("Extract file using nodejs", () => {

archive.close();
}, 5000);

});
12 changes: 7 additions & 5 deletions test/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ const startServer = () =>

module.exports = {
setup: async () => {
let browser = isWsl ? await puppeteer.launch({
headless: "new",
executablePath: "google-chrome",
args: ["--no-sandbox"],
}) : await puppeteer.launch({headless: 'new'});
let browser = isWsl
? await puppeteer.launch({
headless: "new",
executablePath: "google-chrome",
args: ["--no-sandbox"],
})
: await puppeteer.launch({ headless: "new" });

let page = await browser.newPage();
await page.setViewport({ width, height });
Expand Down

0 comments on commit 81fff4b

Please sign in to comment.