Skip to content

Commit a10059f

Browse files
authored
esm (#790)
1 parent bb23b9b commit a10059f

31 files changed

+2209
-2305
lines changed

.github/workflows/nodejs.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [14.x, 16.x, 18.x, 20.x]
17+
node-version: [18.x, 20.x]
1818

1919
steps:
20-
- uses: actions/checkout@v4.2.1
21-
- name: Use Node.js ${{ matrix.node-version }}
22-
uses: actions/setup-node@v4.0.4
23-
with:
24-
node-version: ${{ matrix.node-version }}
25-
- name: npm install and test
26-
run: |
27-
npm ci
28-
npm test
29-
env:
30-
CI: true
20+
- uses: actions/checkout@v4.2.1
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4.0.4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- name: npm install and test
26+
run: |
27+
npm ci
28+
npm test
29+
env:
30+
CI: true

.github/workflows/npmpublish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v4.2.1
1212
- uses: actions/setup-node@v4.0.4
1313
with:
14-
node-version: 16
14+
node-version: 20
1515
- run: npm ci
1616
- run: npm test
1717

@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@v4.2.1
2323
- uses: actions/setup-node@v4.0.4
2424
with:
25-
node-version: 16
25+
node-version: 20
2626
registry-url: https://registry.npmjs.org/
2727
- run: npm ci
2828
- run: npm publish

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ignore artifacts:
2+
build
3+
coverage

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Changelog
22

3+
**8.0.0** - <small>_October 17, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.1...8.0.0)
4+
35
**7.0.1** - <small>_March 9, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/7.0.0...7.0.1)
46

57
**7.0.0** - <small>_February 28, 2024_</small> — [Diff](https://github.com/archiverjs/node-archiver/compare/6.0.2...7.0.0)

CONTRIBUTING.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
#### Code Style Guide
44

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

107
#### Tests
118

12-
* tests should be added to the nodeunit configs in `tests/`
13-
* tests can be run with `npm test`
14-
* see existing tests for guidance
9+
- tests should be added in `test/`
10+
- tests can be run with `npm test`
11+
- see existing tests for guidance

README.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,34 @@ npm install archiver --save
1313
## Quick Start
1414

1515
```js
16-
// require modules
17-
const fs = require('fs');
18-
const archiver = require('archiver');
16+
import fs from "fs";
17+
import { ZipArchive } from "archiver";
1918

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

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

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

4041
// good practice to catch warnings (ie stat failures and other non-blocking errors)
41-
archive.on('warning', function(err) {
42-
if (err.code === 'ENOENT') {
42+
archive.on("warning", function (err) {
43+
if (err.code === "ENOENT") {
4344
// log warning
4445
} else {
4546
// throw error
@@ -48,35 +49,35 @@ archive.on('warning', function(err) {
4849
});
4950

5051
// good practice to catch this error explicitly
51-
archive.on('error', function(err) {
52+
archive.on("error", function (err) {
5253
throw err;
5354
});
5455

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

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

6263
// append a file from string
63-
archive.append('string cheese!', { name: 'file2.txt' });
64+
archive.append("string cheese!", { name: "file2.txt" });
6465

6566
// append a file from buffer
66-
const buffer3 = Buffer.from('buff it!');
67-
archive.append(buffer3, { name: 'file3.txt' });
67+
const buffer3 = Buffer.from("buff it!");
68+
archive.append(buffer3, { name: "file3.txt" });
6869

6970
// append a file
70-
archive.file('file1.txt', { name: 'file4.txt' });
71+
archive.file("file1.txt", { name: "file4.txt" });
7172

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

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

7879
// append files from a glob pattern
79-
archive.glob('file*.txt', {cwd:__dirname});
80+
archive.glob("file*.txt", { cwd: __dirname });
8081

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

8889
Archiver ships with out of the box support for TAR and ZIP archives.
89-
90-
You can register additional formats with `registerFormat`.
91-
92-
You can check if format already exists before to register a new one with `isRegisteredFormat`.

benchmark/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ function binaryBuffer(n) {
22
var buffer = Buffer.alloc(n);
33

44
for (var i = 0; i < n; i++) {
5-
buffer.writeUInt8(i&255, i);
5+
buffer.writeUInt8(i & 255, i);
66
}
77

88
return buffer;
99
}
1010

11-
module.exports.binaryBuffer = binaryBuffer;
11+
module.exports.binaryBuffer = binaryBuffer;

benchmark/simple/pack-zip.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var fs = require('fs');
1+
var fs = require("fs");
22

3-
var mkdir = require('mkdirp');
4-
var streamBench = require('stream-bench');
3+
var mkdir = require("mkdirp");
4+
var streamBench = require("stream-bench");
55

6-
var archiver = require('../../');
7-
var common = require('../common');
6+
var archiver = require("../../");
7+
var common = require("../common");
88

99
var binaryBuffer = common.binaryBuffer;
1010

@@ -30,29 +30,27 @@ if (process.argv[2]) {
3030
}
3131
}
3232

33-
var archive = archiver('zip', {
33+
var archive = archiver("zip", {
3434
zlib: {
35-
level: level
36-
}
35+
level: level,
36+
},
3737
});
3838

3939
if (file === false) {
40-
mkdir.sync('tmp');
40+
mkdir.sync("tmp");
4141

42-
file = 'tmp/20mb.dat';
42+
file = "tmp/20mb.dat";
4343
fs.writeFileSync(file, binaryBuffer(BITS_IN_MBYTE * 20));
4444
}
4545

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

4848
var bench = streamBench({
4949
logReport: true,
5050
interval: 500,
51-
dump: true
51+
dump: true,
5252
});
5353

5454
archive.pipe(bench);
5555

56-
archive
57-
.file(file, { name: 'large file' })
58-
.finalize();
56+
archive.file(file, { name: "large file" }).finalize();

examples/express.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
var app = require('express')();
2-
var archiver = require('archiver');
3-
var p = require('path');
1+
var app = require("express")();
2+
var archiver = require("archiver");
3+
var p = require("path");
44

5-
app.get('/', function(req, res) {
5+
app.get("/", function (req, res) {
6+
var archive = archiver("zip");
67

7-
var archive = archiver('zip');
8-
9-
archive.on('error', function(err) {
10-
res.status(500).send({error: err.message});
8+
archive.on("error", function (err) {
9+
res.status(500).send({ error: err.message });
1110
});
1211

1312
//on stream closed we can end the request
14-
archive.on('end', function() {
15-
console.log('Archive wrote %d bytes', archive.pointer());
13+
archive.on("end", function () {
14+
console.log("Archive wrote %d bytes", archive.pointer());
1615
});
1716

1817
//set the archive name
19-
res.attachment('archive-name.zip');
18+
res.attachment("archive-name.zip");
2019

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

24-
var files = [__dirname + '/fixtures/file1.txt', __dirname + '/fixtures/file2.txt'];
23+
var files = [
24+
__dirname + "/fixtures/file1.txt",
25+
__dirname + "/fixtures/file2.txt",
26+
];
2527

26-
for(var i in files) {
28+
for (var i in files) {
2729
archive.file(files[i], { name: p.basename(files[i]) });
2830
}
2931

30-
var directories = [__dirname + '/fixtures/somedir']
32+
var directories = [__dirname + "/fixtures/somedir"];
3133

32-
for(var i in directories) {
33-
archive.directory(directories[i], directories[i].replace(__dirname + '/fixtures', ''));
34+
for (var i in directories) {
35+
archive.directory(
36+
directories[i],
37+
directories[i].replace(__dirname + "/fixtures", ""),
38+
);
3439
}
3540

3641
archive.finalize();
37-
3842
});
3943

4044
app.listen(3000);

examples/pack-tar.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
var fs = require('fs');
1+
var fs = require("fs");
22

3-
var archiver = require('archiver');
3+
var archiver = require("archiver");
44

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

8-
output.on('close', function() {
9-
console.log(archive.pointer() + ' total bytes');
10-
console.log('archiver has been finalized and the output file descriptor has closed.');
8+
output.on("close", function () {
9+
console.log(archive.pointer() + " total bytes");
10+
console.log(
11+
"archiver has been finalized and the output file descriptor has closed.",
12+
);
1113
});
1214

13-
archive.on('error', function(err) {
15+
archive.on("error", function (err) {
1416
throw err;
1517
});
1618

1719
archive.pipe(output);
1820

19-
var file1 = __dirname + '/fixtures/file1.txt';
20-
var file2 = __dirname + '/fixtures/file2.txt';
21+
var file1 = __dirname + "/fixtures/file1.txt";
22+
var file2 = __dirname + "/fixtures/file2.txt";
2123

2224
archive
23-
.append(fs.createReadStream(file1), { name: 'file1.txt' })
24-
.append(fs.createReadStream(file2), { name: 'file2.txt' })
25-
.finalize();
25+
.append(fs.createReadStream(file1), { name: "file1.txt" })
26+
.append(fs.createReadStream(file2), { name: "file2.txt" })
27+
.finalize();

0 commit comments

Comments
 (0)