Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup-for-scripts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '24'
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0
with:
run_install: |
- args: [--filter, ., --filter, '{./scripts}...']
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
node-version: '24'

- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0

- id: matrix
run: |
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
printf "Aborting: symlinks found:\n%s" "$symlinks"; exit 1
fi

- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0

- name: Get pnpm cache info
id: pnpm-cache
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
id: suggestions-dir
run: echo "path=$(node ./scripts/get-suggestions-dir.js)" >> "$GITHUB_OUTPUT"

- uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: ${{ steps.suggestions-dir.outputs.path }}
merge-multiple: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pnpm-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: '24'
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v4.4.0

- name: Get pnpm cache info
id: pnpm-cache
Expand Down
2 changes: 2 additions & 0 deletions types/adm-zip/adm-zip-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", false, true);
function isAdmZipEntry(obj: any): obj is AdmZip.IZipEntry {
return obj !== null && typeof obj === "object" && typeof obj["entryName"] === "string";
}

zip.toBuffer(); // $ExpectType Buffer<ArrayBuffer>
6 changes: 3 additions & 3 deletions types/adm-zip/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ declare class AdmZip {
/**
* Returns the content of the entire zip file.
*/
toBuffer(): Buffer;
toBuffer(): Buffer<ArrayBuffer>;
/**
* Asynchronously returns the content of the entire zip file.
* @param onSuccess called with the content of the zip file, once it has been generated.
Expand All @@ -235,15 +235,15 @@ declare class AdmZip {
* @param onItemEnd called after an entry is compressed.
*/
toBuffer(
onSuccess: (buffer: Buffer) => void,
onSuccess: (buffer: Buffer<ArrayBuffer>) => void,
onFail?: (...args: any[]) => void,
onItemStart?: (name: string) => void,
onItemEnd?: (name: string) => void,
): void;
/**
* Asynchronously convert the promise to a Buffer
*/
toBufferPromise(): Promise<Buffer>;
toBufferPromise(): Promise<Buffer<ArrayBuffer>>;
}

declare namespace AdmZip {
Expand Down
6 changes: 6 additions & 0 deletions types/adm-zip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"projects": [
"https://github.com/cthackers/adm-zip"
],
"types": "index",
"typesVersions": {
"<=5.6": {
"*": ["ts5.6/*"]
}
},
"dependencies": {
"@types/node": "*"
},
Expand Down
102 changes: 102 additions & 0 deletions types/adm-zip/ts5.6/adm-zip-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import AdmZip = require("adm-zip");
import util = require("adm-zip/util");
const { Constants } = util;

// reading archives
// reading archive causes error
try {
const zip = new AdmZip("./my_file.zip");
} catch (e: unknown) {
const error = e as Error;
switch (error.message) {
case util.Errors.INVALID_FORMAT:
// handle specific error
throw new Error("Invalid zip format");
default:
// handle other errors
throw error;
}
}
// reading archive successfully
const zip = new AdmZip("./my_file.zip");
if (!zip.test()) {
throw new Error("invalid zip?");
}
const zipEntries: AdmZip.IZipEntry[] = zip.getEntries(); // an array of ZipEntry records

zipEntries.forEach(zipEntry => {
console.log(zipEntry.toString()); // outputs zip entries information
if (zipEntry.entryName === "my_file.txt" && zipEntry.header.size < 1000) {
console.log(zipEntry.getData().toString("utf8"));
zipEntry.getDataAsync((data, err) => console.log(err ? "Error: " + err : data.toString("utf8")));
}
});
// outputs the content of some_folder/my_file.txt
console.log(zip.readAsText("some_folder/my_file.txt"));
// same async
zip.readAsTextAsync("my_file.txt", (data, err) => console.log(err ? "Error: " + err : data));
// extracts the specified file to the specified location
zip.extractEntryTo(/*entry name*/ "some_folder/my_file.txt", /*target path*/ "/home/me/tempfolder", /*overwrite*/ true);
// extracts everything
zip.extractAllTo(/*target path*/ "/home/me/zipcontent/", /*overwrite*/ true);
// extracts everything and calls callback -> async extracction
zip.extractAllToAsync(
/*target path*/ "/home/me/zipcontent/",
/*overwrite*/ true,
/*keepOriginalPermission*/ false,
/*callback*/ (error?: Error) => {},
);

// creating archives
new AdmZip();
// creating archives with options
new AdmZip(undefined, { method: Constants.DEFLATED });

// add file directly
const addedEntry = zip.addFile("test.txt", new Buffer("inner content of the file"), "entry comment goes here");
console.log("added", addedEntry.name);
processZipEntry(addedEntry);
// add local file
zip.addLocalFile("/home/me/some_picture.png");
// get everything as a buffer
const willSendthis = zip.toBuffer();

zip.toBuffer(
buffer => console.log(buffer.length),
() => {},
name => console.log(name),
name => console.log(name),
);
// or write everything to disk
zip.writeZip(/*target file name*/ "/home/me/files.zip");

function processZipEntry(zipEntry: AdmZip.IZipEntry) {
console.log("comment", zipEntry.comment);
}

// tests taken from examples at https://github.com/cthackers/adm-zip/wiki/ADM-ZIP
import Zip = require("adm-zip");
// loads and parses existing zip file local_file.zip
new Zip("local_file.zip");
// creates new in memory zip
new Zip();
// loads and parses existing zip file local_file.zip
new Zip("local_file.zip");
// get all entries and iterate them
zip.getEntries().forEach(entry => {
const entryName = entry.entryName;
const decompressedData = zip.readFile(entry); // decompressed buffer of the entry
console.log(zip.readAsText(entry)); // outputs the decompressed content of the entry
});

// will extract the file myfile.txt from the archive to /home/user/folder/subfolder/myfile.txt
zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", true, true);

// will extract the file myfile.txt from the archive to /home/user/myfile.txt
zip.extractEntryTo("folder/subfolder/myfile.txt", "/home/user/", false, true);

function isAdmZipEntry(obj: any): obj is AdmZip.IZipEntry {
return obj !== null && typeof obj === "object" && typeof obj["entryName"] === "string";
}

zip.toBuffer(); // $ExpectType Buffer
Loading