byteclubfr / copycast

Live remote copy-pasta explorer for training sessions
39 stars 0 forks source link

PDF broken in generated archive #25

Closed naholyr closed 7 years ago

naholyr commented 8 years ago

Scenario:

naholyr commented 8 years ago

Generated zip: formation-node-powidian (1).zip

naholyr commented 7 years ago

Fully reproductible, it seems like a bug in easy-zip. For the record, I ran a benchmark of a few Zip solutions:

const files = [ /* bunch of files, including a PDF */ ]

;(() => {
  const { EasyZip: Zip } = require('easy-zip')
  const zip = new Zip()
  zip.batchAdd(files.map(f => ({ source: f, target: f })), () => {
    zip.writeToFile('easy-zip.zip', err => {
      if (err) {
        console.error('easy-zip', err)
      }
    })
  })
})()

;(() => {
  const { EasyZip: Zip } = require('easy-zip2')
  const zip = new Zip()
  zip.batchAdd(files.map(f => ({ source: f, target: f })), () => {
    zip.writeToFile('easy-zip2.zip', err => {
      if (err) {
        console.error('easy-zip2', err)
      }
    })
  })
})()

;(() => {
  require('zipit')({
    input: files
  }, (err, buffer) => {
    if (err) {
      console.error('zipit', err)
    } else {
      require('fs').writeFile('zipit.zip', buffer, err => {
        if (err) {
          console.error('zipit (2)', err)
        }
      })
    }
  })
})

;(() => {
  const { ZipFile } = require('yazl')
  const zip = new ZipFile()
  files.forEach(file => zip.addFile(file, file))
  zip.outputStream.pipe(require('fs').createWriteStream('yazl.zip'))
    .on('close', () => { /* end */ })
    .on('error', err => console.error('yazl', err))
  zip.end()
})()

;(() => {
  const archiver = require('archiver')
  const zip = archiver('zip', {})
  files.forEach(file => zip.file(file))
  zip.pipe(require('fs').createWriteStream('archiver.zip'))
    .on('close', () => { /* end */ })
    .on('error', err => console.error('yazl', err))
  zip.finalize()
})()

Outputs:

3096K   archiver.zip
3108K   easy-zip.zip
3104K   easy-zip2.zip
3104K   yazl.zip

Then running unzip command on each of them:

Damn you, easy-zip! OK, then, archiver produces the smallest file but 8K are neglictible. Let's talk about time, running each of them independently (with time, run twice to double-check):

Each execution gave a similar result: yazl is almost twice as fast, consuming less memory, and generating a working zip.

THANK YOU!