Skip to content

Commit

Permalink
esm
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Oct 18, 2024
1 parent bb23b9b commit f2479b5
Show file tree
Hide file tree
Showing 31 changed files with 2,209 additions and 2,305 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: npm install and test
run: |
npm ci
npm test
env:
CI: true
- uses: actions/[email protected]
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/[email protected]
with:
node-version: ${{ matrix.node-version }}
- name: npm install and test
run: |
npm ci
npm test
env:
CI: true
4 changes: 2 additions & 2 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 16
node-version: 20
- run: npm ci
- run: npm test

Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
node-version: 16
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
Expand Down
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Changelog

**8.0.0** - <small>_October 17, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.1...8.0.0)

**7.0.1** - <small>_March 9, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.0...7.0.1)

**7.0.0** - <small>_February 28, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/6.0.2...7.0.0)
Expand Down
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

#### Code Style Guide

* code should be indented with 2 spaces
* single quotes should be used where feasible
* commas should be followed by a single space (function params, etc)
* variable declaration should include `var`, [no multiple declarations](http://benalman.com/news/2012/05/multiple-var-statements-javascript/)
- code should be ran through `prettier`

#### Tests

* tests should be added to the nodeunit configs in `tests/`
* tests can be run with `npm test`
* see existing tests for guidance
- tests should be added in `test/`
- tests can be run with `npm test`
- see existing tests for guidance
51 changes: 24 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@ npm install archiver --save
## Quick Start

```js
// require modules
const fs = require('fs');
const archiver = require('archiver');
import fs from "fs";
import { ZipArchive } from "archiver";

// create a file to stream archive data to.
const output = fs.createWriteStream(__dirname + '/example.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level.
const output = fs.createWriteStream(__dirname + "/example.zip");
const archive = new ZipArchive({
zlib: { level: 9 }, // Sets the compression level.
});

// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed.",
);
});

// This event is fired when the data source is drained no matter what was the data source.
// It is not part of this library but rather from the NodeJS Stream API.
// @see: https://nodejs.org/api/stream.html#stream_event_end
output.on('end', function() {
console.log('Data has been drained');
output.on("end", function () {
console.log("Data has been drained");
});

// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', function(err) {
if (err.code === 'ENOENT') {
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
// log warning
} else {
// throw error
Expand All @@ -48,35 +49,35 @@ archive.on('warning', function(err) {
});

// good practice to catch this error explicitly
archive.on('error', function(err) {
archive.on("error", function (err) {
throw err;
});

// pipe archive data to the file
archive.pipe(output);

// append a file from stream
const file1 = __dirname + '/file1.txt';
archive.append(fs.createReadStream(file1), { name: 'file1.txt' });
const file1 = __dirname + "/file1.txt";
archive.append(fs.createReadStream(file1), { name: "file1.txt" });

// append a file from string
archive.append('string cheese!', { name: 'file2.txt' });
archive.append("string cheese!", { name: "file2.txt" });

// append a file from buffer
const buffer3 = Buffer.from('buff it!');
archive.append(buffer3, { name: 'file3.txt' });
const buffer3 = Buffer.from("buff it!");
archive.append(buffer3, { name: "file3.txt" });

// append a file
archive.file('file1.txt', { name: 'file4.txt' });
archive.file("file1.txt", { name: "file4.txt" });

// append files from a sub-directory and naming it `new-subdir` within the archive
archive.directory('subdir/', 'new-subdir');
archive.directory("subdir/", "new-subdir");

// append files from a sub-directory, putting its contents at the root of archive
archive.directory('subdir/', false);
archive.directory("subdir/", false);

// append files from a glob pattern
archive.glob('file*.txt', {cwd:__dirname});
archive.glob("file*.txt", { cwd: __dirname });

// finalize the archive (ie we are done appending files but streams have to finish yet)
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
Expand All @@ -86,7 +87,3 @@ archive.finalize();
## Formats

Archiver ships with out of the box support for TAR and ZIP archives.

You can register additional formats with `registerFormat`.

You can check if format already exists before to register a new one with `isRegisteredFormat`.
4 changes: 2 additions & 2 deletions benchmark/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ function binaryBuffer(n) {
var buffer = Buffer.alloc(n);

for (var i = 0; i < n; i++) {
buffer.writeUInt8(i&255, i);
buffer.writeUInt8(i & 255, i);
}

return buffer;
}

module.exports.binaryBuffer = binaryBuffer;
module.exports.binaryBuffer = binaryBuffer;
28 changes: 13 additions & 15 deletions benchmark/simple/pack-zip.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var fs = require('fs');
var fs = require("fs");

var mkdir = require('mkdirp');
var streamBench = require('stream-bench');
var mkdir = require("mkdirp");
var streamBench = require("stream-bench");

var archiver = require('../../');
var common = require('../common');
var archiver = require("../../");
var common = require("../common");

var binaryBuffer = common.binaryBuffer;

Expand All @@ -30,29 +30,27 @@ if (process.argv[2]) {
}
}

var archive = archiver('zip', {
var archive = archiver("zip", {
zlib: {
level: level
}
level: level,
},
});

if (file === false) {
mkdir.sync('tmp');
mkdir.sync("tmp");

file = 'tmp/20mb.dat';
file = "tmp/20mb.dat";
fs.writeFileSync(file, binaryBuffer(BITS_IN_MBYTE * 20));
}

console.log('zlib level: ' + level);
console.log("zlib level: " + level);

var bench = streamBench({
logReport: true,
interval: 500,
dump: true
dump: true,
});

archive.pipe(bench);

archive
.file(file, { name: 'large file' })
.finalize();
archive.file(file, { name: "large file" }).finalize();
38 changes: 21 additions & 17 deletions examples/express.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
var app = require('express')();
var archiver = require('archiver');
var p = require('path');
var app = require("express")();
var archiver = require("archiver");
var p = require("path");

app.get('/', function(req, res) {
app.get("/", function (req, res) {
var archive = archiver("zip");

var archive = archiver('zip');

archive.on('error', function(err) {
res.status(500).send({error: err.message});
archive.on("error", function (err) {
res.status(500).send({ error: err.message });
});

//on stream closed we can end the request
archive.on('end', function() {
console.log('Archive wrote %d bytes', archive.pointer());
archive.on("end", function () {
console.log("Archive wrote %d bytes", archive.pointer());
});

//set the archive name
res.attachment('archive-name.zip');
res.attachment("archive-name.zip");

//this is the streaming magic
archive.pipe(res);

var files = [__dirname + '/fixtures/file1.txt', __dirname + '/fixtures/file2.txt'];
var files = [
__dirname + "/fixtures/file1.txt",
__dirname + "/fixtures/file2.txt",
];

for(var i in files) {
for (var i in files) {
archive.file(files[i], { name: p.basename(files[i]) });
}

var directories = [__dirname + '/fixtures/somedir']
var directories = [__dirname + "/fixtures/somedir"];

for(var i in directories) {
archive.directory(directories[i], directories[i].replace(__dirname + '/fixtures', ''));
for (var i in directories) {
archive.directory(
directories[i],
directories[i].replace(__dirname + "/fixtures", ""),
);
}

archive.finalize();

});

app.listen(3000);
28 changes: 15 additions & 13 deletions examples/pack-tar.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
var fs = require('fs');
var fs = require("fs");

var archiver = require('archiver');
var archiver = require("archiver");

var output = fs.createWriteStream(__dirname + '/example-output.tar');
var archive = archiver('tar');
var output = fs.createWriteStream(__dirname + "/example-output.tar");
var archive = archiver("tar");

output.on('close', function() {
console.log(archive.pointer() + ' total bytes');
console.log('archiver has been finalized and the output file descriptor has closed.');
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed.",
);
});

archive.on('error', function(err) {
archive.on("error", function (err) {
throw err;
});

archive.pipe(output);

var file1 = __dirname + '/fixtures/file1.txt';
var file2 = __dirname + '/fixtures/file2.txt';
var file1 = __dirname + "/fixtures/file1.txt";
var file2 = __dirname + "/fixtures/file2.txt";

archive
.append(fs.createReadStream(file1), { name: 'file1.txt' })
.append(fs.createReadStream(file2), { name: 'file2.txt' })
.finalize();
.append(fs.createReadStream(file1), { name: "file1.txt" })
.append(fs.createReadStream(file2), { name: "file2.txt" })
.finalize();
Loading

0 comments on commit f2479b5

Please sign in to comment.