{"action":"created","issue":{"url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/101","repository_url":"https://api.github.com/repos/thejoshwolfe/yauzl","labels_url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/101/comments","events_url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/101/events","html_url":"https://github.com/thejoshwolfe/yauzl/issues/101","id":391531238,"node_id":"MDU6SXNzdWUzOTE1MzEyMzg=","number":101,"title":"File permissions changed while unzipping.","user":{"login":"rash805115","id":4465074,"node_id":"MDQ6VXNlcjQ0NjUwNzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4465074?v=4","gravatar_id":"","url":"https://api.github.com/users/rash805115","html_url":"https://github.com/rash805115","followers_url":"https://api.github.com/users/rash805115/followers","following_url":"https://api.github.com/users/rash805115/following{/other_user}","gists_url":"https://api.github.com/users/rash805115/gists{/gist_id}","starred_url":"https://api.github.com/users/rash805115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rash805115/subscriptions","organizations_url":"https://api.github.com/users/rash805115/orgs","repos_url":"https://api.github.com/users/rash805115/repos","events_url":"https://api.github.com/users/rash805115/events{/privacy}","received_events_url":"https://api.github.com/users/rash805115/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-12-17T01:56:11Z","updated_at":"2018-12-17T11:08:17Z","closed_at":null,"author_association":"NONE","body":"Yauzl library is incorrectly unzipping my file permissions. Below is a test file.\r\n\r\n```js\r\nconst AdmZip = require('adm-zip')\r\nconst fs = require('fs-extra')\r\nconst path = require('path')\r\nconst yauzl = require('yauzl')\r\nconst yazl = require('yazl')\r\n\r\n// Create an archive of a file whose permission is 755.\r\nlet createArchive = function () {\r\n  return new Promise(function (resolve) {\r\n    let zip = new yazl.ZipFile()\r\n    zip.addFile('./node_modules/webpack-dev-server/bin/webpack-dev-server.js', 'webpack-dev-server.js')\r\n    zip.end(function () {\r\n      zip.outputStream\r\n        .pipe(fs.createWriteStream('./test.zip'))\r\n        .on('close', function () {\r\n          resolve()\r\n        })\r\n    })\r\n  })\r\n}\r\n\r\n// Check the permission of the file inside zip. It should be same as what we archived.\r\nlet checkArchive = function () {\r\n  return new Promise(function (resolve) {\r\n    let outputZip = new AdmZip('./test.zip')\r\n    resolve(outputZip.getEntry('webpack-dev-server.js'))\r\n  })\r\n}\r\n\r\n// Extract the file and check its permission. It should be the same as the original permission.\r\nlet extractArchive = function () {\r\n  return new Promise(function (resolve) {\r\n    yauzl.open('./test.zip', {lazyEntries: true}, (error, zip) => {\r\n      zip.on('end', () => { resolve() })\r\n      zip.on('entry', (entry) => {\r\n        zip.openReadStream(entry, function (error, readStream) {\r\n          if (error) return zip.emit('error', error)\r\n\r\n          // Save current entry. Then read next.\r\n          fs.ensureFile(path.join('./', entry.fileName), (error) => {\r\n            if (error) return zip.emit('error', error)\r\n\r\n            let outputStream = fs.createWriteStream('./' + entry.fileName)\r\n            outputStream.on('error', (error) => { zip.emit('error', error) })\r\n            outputStream.on('finish', () => { zip.readEntry() })\r\n\r\n            readStream.on('error', (error) => { zip.emit('error', error) })\r\n            readStream.pipe(outputStream)\r\n          })\r\n        })\r\n      })\r\n\r\n      zip.readEntry()\r\n    })\r\n  })\r\n}\r\n\r\nlet modes = {}\r\n\r\nlet originalMode = fs.statSync('./node_modules/webpack-dev-server/bin/webpack-dev-server.js')\r\nmodes['original'] = ((originalMode.mode << 16) >>> 0)\r\n\r\ncreateArchive()\r\n  .then(function () {\r\n    return checkArchive()\r\n  })\r\n  .then(function (permission) {\r\n    modes['zipped'] = permission.header.attr\r\n    return extractArchive()\r\n  })\r\n  .then(function () {\r\n    let unzippedMode = fs.statSync('./webpack-dev-server.js')\r\n    modes['unzipped'] = ((unzippedMode.mode << 16) >>> 0)\r\n\r\n    console.log('Original ' + modes['original']) // 33261 i.e. 755\r\n    console.log('Zipped   ' + modes['zipped']) // 33261 i.e. 755\r\n    console.log('Unzipped ' + modes['unzipped']) // 33188 i.e. 644\r\n  })\r\n```\r\n\r\nOutput\r\n====\r\n```\r\nOriginal 2179792896\r\nZipped   2179792896\r\nUnzipped 2175008768\r\n```\r\n\r\nI have also verified that in [Line 287](https://github.com/thejoshwolfe/yauzl/blob/master/index.js#L287), the same value as `zipped` is read, so I am not sure why the file is not set with correct permissions."},"comment":{"url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/comments/447807868","html_url":"https://github.com/thejoshwolfe/yauzl/issues/101#issuecomment-447807868","issue_url":"https://api.github.com/repos/thejoshwolfe/yauzl/issues/101","id":447807868,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NzgwNzg2OA==","user":{"login":"rash805115","id":4465074,"node_id":"MDQ6VXNlcjQ0NjUwNzQ=","avatar_url":"https://avatars1.githubusercontent.com/u/4465074?v=4","gravatar_id":"","url":"https://api.github.com/users/rash805115","html_url":"https://github.com/rash805115","followers_url":"https://api.github.com/users/rash805115/followers","following_url":"https://api.github.com/users/rash805115/following{/other_user}","gists_url":"https://api.github.com/users/rash805115/gists{/gist_id}","starred_url":"https://api.github.com/users/rash805115/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rash805115/subscriptions","organizations_url":"https://api.github.com/users/rash805115/orgs","repos_url":"https://api.github.com/users/rash805115/repos","events_url":"https://api.github.com/users/rash805115/events{/privacy}","received_events_url":"https://api.github.com/users/rash805115/received_events","type":"User","site_admin":false},"created_at":"2018-12-17T11:08:17Z","updated_at":"2018-12-17T11:08:17Z","author_association":"NONE","body":"Ah I see. Thank you for explanation. I will have to change this line.\r\n```node\r\nlet outputStream = fs.createWriteStream('./' + entry.fileName, {mode: entry.externalFileAttributes})\r\n```\r\nBut `externalFileAttributes` is this big number `2179792896` that I am not sure how to convert to `33261` and I couldn't find anything in docs."}}
{"actor":{"display_login":"rash805115"}}