Skip to content

Commit

Permalink
Delete .github/workflows/npmpublish.yml.save
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Oct 14, 2024
1 parent 6d5a6c5 commit f08f5f7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 120 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/npmpublish.yml.save

This file was deleted.

1 change: 1 addition & 0 deletions lib/archivers/zip/zip-archive-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
S_DOS_D,
S_IFDIR,
S_IFREG,
SHORT_MASK,
SHORT_SHIFT,
ZIP64_MAGIC,
} from "./constants.js";
Expand Down
151 changes: 75 additions & 76 deletions lib/archivers/zip/zip-archive-output-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,38 @@ import {
SHORT_ZERO,
SIG_EOCD,
SIG_DD,
SIG_CFH,
SIG_LFH,
SIG_ZIP64_EOCD,
SIG_ZIP64_EOCD_LOC,
VERSION_MADEBY,
ZIP64_EXTRA_ID,
ZIP64_MAGIC,
ZIP64_MAGIC_SHORT,
ZLIB_BEST_SPEED,
} from "./constants.js";
import util from "../../util/index.js";
import zipUtil from "./util.js";
import { getEightBytes, getLongBytes, getShortBytes } from "./util.js";

function _defaults(o) {
if (typeof o !== "object") {
o = {};
}
if (typeof o.zlib !== "object") {
o.zlib = {};
}
if (typeof o.zlib.level !== "number") {
o.zlib.level = ZLIB_BEST_SPEED;
}
o.forceZip64 = !!o.forceZip64;
o.forceLocalTime = !!o.forceLocalTime;
return o;
}

export default class ZipArchiveOutputStream extends ArchiveOutputStream {
constructor(options) {
options = this.options = this._defaults(options);
super(options);
const _options = _defaults(options);
super(_options);
this.options = _options;
this._entry = null;
this._entries = [];
this._archive = {
Expand All @@ -36,8 +54,8 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
finish: false,
finished: false,
processing: false,
forceZip64: options.forceZip64,
forceLocalTime: options.forceLocalTime,
forceZip64: _options.forceZip64,
forceLocalTime: _options.forceLocalTime,
};
}

Expand Down Expand Up @@ -90,21 +108,6 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
source.pipe(smart);
}

_defaults = function (o) {
if (typeof o !== "object") {
o = {};
}
if (typeof o.zlib !== "object") {
o.zlib = {};
}
if (typeof o.zlib.level !== "number") {
o.zlib.level = ZLIB_BEST_SPEED;
}
o.forceZip64 = !!o.forceZip64;
o.forceLocalTime = !!o.forceLocalTime;
return o;
};

_finish() {
this._archive.centralOffset = this.offset;
this._entries.forEach(
Expand Down Expand Up @@ -173,55 +176,53 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
offset = ZIP64_MAGIC;
}
// signature
this.write(zipUtil.getLongBytes(SIG_EOCD));
this.write(getLongBytes(SIG_EOCD));
// disk numbers
this.write(SHORT_ZERO);
this.write(SHORT_ZERO);
// number of entries
this.write(zipUtil.getShortBytes(records));
this.write(zipUtil.getShortBytes(records));
this.write(getShortBytes(records));
this.write(getShortBytes(records));
// length and location of CD
this.write(zipUtil.getLongBytes(size));
this.write(zipUtil.getLongBytes(offset));
this.write(getLongBytes(size));
this.write(getLongBytes(offset));
// archive comment
var comment = this.getComment();
var commentLength = Buffer.byteLength(comment);
this.write(zipUtil.getShortBytes(commentLength));
this.write(getShortBytes(commentLength));
this.write(comment);
}

_writeCentralDirectoryZip64() {
// signature
this.write(zipUtil.getLongBytes(SIG_ZIP64_EOCD));
this.write(getLongBytes(SIG_ZIP64_EOCD));
// size of the ZIP64 EOCD record
this.write(zipUtil.getEightBytes(44));
this.write(getEightBytes(44));
// version made by
this.write(zipUtil.getShortBytes(MIN_VERSION_ZIP64));
this.write(getShortBytes(MIN_VERSION_ZIP64));
// version to extract
this.write(zipUtil.getShortBytes(MIN_VERSION_ZIP64));
this.write(getShortBytes(MIN_VERSION_ZIP64));
// disk numbers
this.write(LONG_ZERO);
this.write(LONG_ZERO);
// number of entries
this.write(zipUtil.getEightBytes(this._entries.length));
this.write(zipUtil.getEightBytes(this._entries.length));
this.write(getEightBytes(this._entries.length));
this.write(getEightBytes(this._entries.length));
// length and location of CD
this.write(zipUtil.getEightBytes(this._archive.centralLength));
this.write(zipUtil.getEightBytes(this._archive.centralOffset));
this.write(getEightBytes(this._archive.centralLength));
this.write(getEightBytes(this._archive.centralOffset));
// extensible data sector
// not implemented at this time
// end of central directory locator
this.write(zipUtil.getLongBytes(SIG_ZIP64_EOCD_LOC));
this.write(getLongBytes(SIG_ZIP64_EOCD_LOC));
// disk number holding the ZIP64 EOCD record
this.write(LONG_ZERO);
// relative offset of the ZIP64 EOCD record
this.write(
zipUtil.getEightBytes(
this._archive.centralOffset + this._archive.centralLength,
),
getEightBytes(this._archive.centralOffset + this._archive.centralLength),
);
// total number of disks
this.write(zipUtil.getLongBytes(1));
this.write(getLongBytes(1));
}

_writeCentralFileHeader(ae) {
Expand All @@ -237,34 +238,32 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
ae.setVersionNeededToExtract(MIN_VERSION_ZIP64);
var extraBuf = Buffer.concat(
[
zipUtil.getShortBytes(ZIP64_EXTRA_ID),
zipUtil.getShortBytes(24),
zipUtil.getEightBytes(ae.getSize()),
zipUtil.getEightBytes(ae.getCompressedSize()),
zipUtil.getEightBytes(ae._offsets.file),
getShortBytes(ZIP64_EXTRA_ID),
getShortBytes(24),
getEightBytes(ae.getSize()),
getEightBytes(ae.getCompressedSize()),
getEightBytes(ae._offsets.file),
],
28,
);
ae.setExtra(extraBuf);
}
// signature
this.write(zipUtil.getLongBytes(constants.SIG_CFH));
this.write(getLongBytes(SIG_CFH));
// version made by
this.write(
zipUtil.getShortBytes((ae.getPlatform() << 8) | constants.VERSION_MADEBY),
);
this.write(getShortBytes((ae.getPlatform() << 8) | VERSION_MADEBY));
// version to extract and general bit flag
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract()));
this.write(getShortBytes(ae.getVersionNeededToExtract()));
this.write(gpb.encode());
// compression method
this.write(zipUtil.getShortBytes(method));
this.write(getShortBytes(method));
// datetime
this.write(zipUtil.getLongBytes(ae.getTimeDos()));
this.write(getLongBytes(ae.getTimeDos()));
// crc32 checksum
this.write(zipUtil.getLongBytes(ae.getCrc()));
this.write(getLongBytes(ae.getCrc()));
// sizes
this.write(zipUtil.getLongBytes(compressedSize));
this.write(zipUtil.getLongBytes(size));
this.write(getLongBytes(compressedSize));
this.write(getLongBytes(size));
var name = ae.getName();
var comment = ae.getComment();
var extra = ae.getCentralDirectoryExtra();
Expand All @@ -273,19 +272,19 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
comment = Buffer.from(comment);
}
// name length
this.write(zipUtil.getShortBytes(name.length));
this.write(getShortBytes(name.length));
// extra length
this.write(zipUtil.getShortBytes(extra.length));
this.write(getShortBytes(extra.length));
// comments length
this.write(zipUtil.getShortBytes(comment.length));
this.write(getShortBytes(comment.length));
// disk number start
this.write(SHORT_ZERO);
// internal attributes
this.write(zipUtil.getShortBytes(ae.getInternalAttributes()));
this.write(getShortBytes(ae.getInternalAttributes()));
// external attributes
this.write(zipUtil.getLongBytes(ae.getExternalAttributes()));
this.write(getLongBytes(ae.getExternalAttributes()));
// relative offset of LFH
this.write(zipUtil.getLongBytes(fileOffset));
this.write(getLongBytes(fileOffset));
// name
this.write(name);
// extra
Expand All @@ -296,16 +295,16 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {

_writeDataDescriptor(ae) {
// signature
this.write(zipUtil.getLongBytes(SIG_DD));
this.write(getLongBytes(SIG_DD));
// crc32 checksum
this.write(zipUtil.getLongBytes(ae.getCrc()));
this.write(getLongBytes(ae.getCrc()));
// sizes
if (ae.isZip64()) {
this.write(zipUtil.getEightBytes(ae.getCompressedSize()));
this.write(zipUtil.getEightBytes(ae.getSize()));
this.write(getEightBytes(ae.getCompressedSize()));
this.write(getEightBytes(ae.getSize()));
} else {
this.write(zipUtil.getLongBytes(ae.getCompressedSize()));
this.write(zipUtil.getLongBytes(ae.getSize()));
this.write(getLongBytes(ae.getCompressedSize()));
this.write(getLongBytes(ae.getSize()));
}
}

Expand All @@ -323,29 +322,29 @@ export default class ZipArchiveOutputStream extends ArchiveOutputStream {
}
ae._offsets.file = this.offset;
// signature
this.write(zipUtil.getLongBytes(SIG_LFH));
this.write(getLongBytes(SIG_LFH));
// version to extract and general bit flag
this.write(zipUtil.getShortBytes(ae.getVersionNeededToExtract()));
this.write(getShortBytes(ae.getVersionNeededToExtract()));
this.write(gpb.encode());
// compression method
this.write(zipUtil.getShortBytes(method));
this.write(getShortBytes(method));
// datetime
this.write(zipUtil.getLongBytes(ae.getTimeDos()));
this.write(getLongBytes(ae.getTimeDos()));
ae._offsets.data = this.offset;
// crc32 checksum and sizes
if (gpb.usesDataDescriptor()) {
this.write(LONG_ZERO);
this.write(LONG_ZERO);
this.write(LONG_ZERO);
} else {
this.write(zipUtil.getLongBytes(ae.getCrc()));
this.write(zipUtil.getLongBytes(ae.getCompressedSize()));
this.write(zipUtil.getLongBytes(ae.getSize()));
this.write(getLongBytes(ae.getCrc()));
this.write(getLongBytes(ae.getCompressedSize()));
this.write(getLongBytes(ae.getSize()));
}
// name length
this.write(zipUtil.getShortBytes(name.length));
this.write(getShortBytes(name.length));
// extra length
this.write(zipUtil.getShortBytes(extra.length));
this.write(getShortBytes(extra.length));
// name
this.write(name);
// extra
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"crc-32": "^1.2.0",
"crc32-stream": "^7.0.0",
"crc32-stream": "^7.0.1",
"is-stream": "^3.0.0",
"normalize-path": "^3.0.0",
"readable-stream": "^4.0.0"
Expand Down
Loading

0 comments on commit f08f5f7

Please sign in to comment.