Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
minor styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jul 5, 2020
1 parent 0d13c43 commit d8251f2
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,13 @@ class ZipExtractor {
// convert external file attr int into a fs stat mode int
const mode = (entry.externalFileAttributes >> 16) & 0xFFFF;
// check if it's a symlink or dir (using stat mode constants)
const symlink = (mode & IFMT) === IFLNK;
let isDir = (mode & IFMT) === IFDIR;
// Failsafe, borrowed from jsZip
if (!isDir && fileName.endsWith('/')) {
isDir = true;
}
// check for windows weird way of specifying a directory
// https://github.com/maxogden/extract-zip/issues/13#issuecomment-154494566
const madeBy = entry.versionMadeBy >> 8;
if (!isDir) {
isDir = (madeBy === 0 && entry.externalFileAttributes === 16);
}
const isSymlink = (mode & IFMT) === IFLNK;
const isDir = (mode & IFMT) === IFDIR
// Failsafe, borrowed from jsZip
|| fileName.endsWith('/')
// check for windows weird way of specifying a directory
// https://github.com/maxogden/extract-zip/issues/13#issuecomment-154494566
|| (entry.versionMadeBy >> 8 === 0 && entry.externalFileAttributes === 16);
const procMode = this.getExtractedMode(mode, isDir) & 0o777;
// always ensure folders are created
const destDir = isDir ? dest : path.dirname(dest);
Expand All @@ -130,7 +125,7 @@ class ZipExtractor {
}

const readStream = await B.promisify(this.zipfile.openReadStream.bind(this.zipfile))(entry);
if (symlink) {
if (isSymlink) {
const link = await getStream(readStream);
await fs.symlink(link, dest);
} else {
Expand Down Expand Up @@ -176,7 +171,7 @@ class ZipExtractor {
* @property {?string} fileNamesEncoding The encoding to use for extracted file names.
* For ZIP archives created on MacOS it is usually expected to be `utf8`.
* By default it is autodetected based on the entry metadata and is only needed to be set explicitly
* if the file has not been created according to the standards, which leads to corrupted file names
* if the particular archive does not comply to the standards, which leads to corrupted file names
* after extraction.
* @property {?number} defaultDirMode [0o755] The default permissions for extracted folders. It is only
* applied when the extractor is unable to retrieve this value for a directory from the archive
Expand All @@ -191,6 +186,7 @@ class ZipExtractor {
*
* @param {string} zipFilePath The full path to the source ZIP file
* @param {string} destDir The full path to the destination folder
* @param {?ExtractAllOptions} opts
*/
async function extractAllTo (zipFilePath, destDir, opts = {}) {
if (!path.isAbsolute(destDir)) {
Expand Down

0 comments on commit d8251f2

Please sign in to comment.