How to use the yauzl.RandomAccessReader function in yauzl

To help you get started, we’ve selected a few yauzl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TimelordUK / jspurefix / src / util / unzip.js View on Github external
// resolve optional parameters
      if (offsetArg == null) offsetArg = 0
      if (lenArg == null && endArg == null) endArg = stats.size
      if (endArg == null) endArg = lenArg + offsetArg
      else if (endArg < 0) endArg = stats.size + endArg
      // validate parameters
      if (offsetArg < 0) throw new Error('--offset < 0')
      if (lenArg < 0) throw new Error('--len < 0')
      if (offsetArg > endArg) throw new Error('--offset > --end')
      if (endArg > stats.size) throw new Error('--end/--len goes past EOF')

      // extend RandomAccessReader
      function MiddleOfFileReader () {
        yauzl.RandomAccessReader.call(this)
      }
      util.inherits(MiddleOfFileReader, yauzl.RandomAccessReader)
      // implement required and option methods
      MiddleOfFileReader.prototype._readStreamForRange = function (start, end) {
        return fs.createReadStream(null, {
          fd: fd,
          // shift the start and end offsets
          start: start + offsetArg,
          end: end + offsetArg - 1, // the -1 is because fs.createReadStream()'s end option is inclusive
          autoClose: false
        })
      }
      MiddleOfFileReader.prototype.read = function (buffer, offset, length, position, callback) {
        // shift the position
        fs.read(fd, buffer, offset, length, position + offsetArg, callback)
      }
      MiddleOfFileReader.prototype.close = function (callback) {
        fs.close(fd, callback)
github TimelordUK / jspurefix / src / util / unzip.js View on Github external
function MiddleOfFileReader () {
        yauzl.RandomAccessReader.call(this)
      }
      util.inherits(MiddleOfFileReader, yauzl.RandomAccessReader)