Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. # yauzl
  2. [![Build Status](https://travis-ci.org/thejoshwolfe/yauzl.svg?branch=master)](https://travis-ci.org/thejoshwolfe/yauzl)
  3. [![Coverage Status](https://img.shields.io/coveralls/thejoshwolfe/yauzl.svg)](https://coveralls.io/r/thejoshwolfe/yauzl)
  4. yet another unzip library for node. For zipping, see
  5. [yazl](https://github.com/thejoshwolfe/yazl).
  6. Design principles:
  7. * Follow the spec.
  8. Don't scan for local file headers.
  9. Read the central directory for file metadata.
  10. (see [No Streaming Unzip API](#no-streaming-unzip-api)).
  11. * Don't block the JavaScript thread.
  12. Use and provide async APIs.
  13. * Keep memory usage under control.
  14. Don't attempt to buffer entire files in RAM at once.
  15. * Never crash (if used properly).
  16. Don't let malformed zip files bring down client applications who are trying to catch errors.
  17. * Catch unsafe file names.
  18. See `validateFileName()`.
  19. ## Usage
  20. ```js
  21. var yauzl = require("yauzl");
  22. yauzl.open("path/to/file.zip", {lazyEntries: true}, function(err, zipfile) {
  23. if (err) throw err;
  24. zipfile.readEntry();
  25. zipfile.on("entry", function(entry) {
  26. if (/\/$/.test(entry.fileName)) {
  27. // Directory file names end with '/'.
  28. // Note that entires for directories themselves are optional.
  29. // An entry's fileName implicitly requires its parent directories to exist.
  30. zipfile.readEntry();
  31. } else {
  32. // file entry
  33. zipfile.openReadStream(entry, function(err, readStream) {
  34. if (err) throw err;
  35. readStream.on("end", function() {
  36. zipfile.readEntry();
  37. });
  38. readStream.pipe(somewhere);
  39. });
  40. }
  41. });
  42. });
  43. ```
  44. See also `examples/` for more usage examples.
  45. ## API
  46. The default for every optional `callback` parameter is:
  47. ```js
  48. function defaultCallback(err) {
  49. if (err) throw err;
  50. }
  51. ```
  52. ### open(path, [options], [callback])
  53. Calls `fs.open(path, "r")` and reads the `fd` effectively the same as `fromFd()` would.
  54. `options` may be omitted or `null`. The defaults are `{autoClose: true, lazyEntries: false, decodeStrings: true, validateEntrySizes: true, strictFileNames: false}`.
  55. `autoClose` is effectively equivalent to:
  56. ```js
  57. zipfile.once("end", function() {
  58. zipfile.close();
  59. });
  60. ```
  61. `lazyEntries` indicates that entries should be read only when `readEntry()` is called.
  62. If `lazyEntries` is `false`, `entry` events will be emitted as fast as possible to allow `pipe()`ing
  63. file data from all entries in parallel.
  64. This is not recommended, as it can lead to out of control memory usage for zip files with many entries.
  65. See [issue #22](https://github.com/thejoshwolfe/yauzl/issues/22).
  66. If `lazyEntries` is `true`, an `entry` or `end` event will be emitted in response to each call to `readEntry()`.
  67. This allows processing of one entry at a time, and will keep memory usage under control for zip files with many entries.
  68. `decodeStrings` is the default and causes yauzl to decode strings with `CP437` or `UTF-8` as required by the spec.
  69. The exact effects of turning this option off are:
  70. * `zipfile.comment`, `entry.fileName`, and `entry.fileComment` will be `Buffer` objects instead of `String`s.
  71. * Any Info-ZIP Unicode Path Extra Field will be ignored. See `extraFields`.
  72. * Automatic file name validation will not be performed. See `validateFileName()`.
  73. `validateEntrySizes` is the default and ensures that an entry's reported uncompressed size matches its actual uncompressed size.
  74. This check happens as early as possible, which is either before emitting each `"entry"` event (for entries with no compression),
  75. or during the `readStream` piping after calling `openReadStream()`.
  76. See `openReadStream()` for more information on defending against zip bomb attacks.
  77. When `strictFileNames` is `false` (the default) and `decodeStrings` is `true`,
  78. all backslash (`\`) characters in each `entry.fileName` are replaced with forward slashes (`/`).
  79. The spec forbids file names with backslashes,
  80. but Microsoft's `System.IO.Compression.ZipFile` class in .NET versions 4.5.0 until 4.6.1
  81. creates non-conformant zipfiles with backslashes in file names.
  82. `strictFileNames` is `false` by default so that clients can read these
  83. non-conformant zipfiles without knowing about this Microsoft-specific bug.
  84. When `strictFileNames` is `true` and `decodeStrings` is `true`,
  85. entries with backslashes in their file names will result in an error. See `validateFileName()`.
  86. When `decodeStrings` is `false`, `strictFileNames` has no effect.
  87. The `callback` is given the arguments `(err, zipfile)`.
  88. An `err` is provided if the End of Central Directory Record cannot be found, or if its metadata appears malformed.
  89. This kind of error usually indicates that this is not a zip file.
  90. Otherwise, `zipfile` is an instance of `ZipFile`.
  91. ### fromFd(fd, [options], [callback])
  92. Reads from the fd, which is presumed to be an open .zip file.
  93. Note that random access is required by the zip file specification,
  94. so the fd cannot be an open socket or any other fd that does not support random access.
  95. `options` may be omitted or `null`. The defaults are `{autoClose: false, lazyEntries: false, decodeStrings: true, validateEntrySizes: true, strictFileNames: false}`.
  96. See `open()` for the meaning of the options and callback.
  97. ### fromBuffer(buffer, [options], [callback])
  98. Like `fromFd()`, but reads from a RAM buffer instead of an open file.
  99. `buffer` is a `Buffer`.
  100. If a `ZipFile` is acquired from this method,
  101. it will never emit the `close` event,
  102. and calling `close()` is not necessary.
  103. `options` may be omitted or `null`. The defaults are `{lazyEntries: false, decodeStrings: true, validateEntrySizes: true, strictFileNames: false}`.
  104. See `open()` for the meaning of the options and callback.
  105. The `autoClose` option is ignored for this method.
  106. ### fromRandomAccessReader(reader, totalSize, [options], [callback])
  107. This method of reading a zip file allows clients to implement their own back-end file system.
  108. For example, a client might translate read calls into network requests.
  109. The `reader` parameter must be of a type that is a subclass of
  110. [RandomAccessReader](#class-randomaccessreader) that implements the required methods.
  111. The `totalSize` is a Number and indicates the total file size of the zip file.
  112. `options` may be omitted or `null`. The defaults are `{autoClose: true, lazyEntries: false, decodeStrings: true, validateEntrySizes: true, strictFileNames: false}`.
  113. See `open()` for the meaning of the options and callback.
  114. ### dosDateTimeToDate(date, time)
  115. Converts MS-DOS `date` and `time` data into a JavaScript `Date` object.
  116. Each parameter is a `Number` treated as an unsigned 16-bit integer.
  117. Note that this format does not support timezones,
  118. so the returned object will use the local timezone.
  119. ### validateFileName(fileName)
  120. Returns `null` or a `String` error message depending on the validity of `fileName`.
  121. If `fileName` starts with `"/"` or `/[A-Za-z]:\//` or if it contains `".."` path segments or `"\\"`,
  122. this function returns an error message appropriate for use like this:
  123. ```js
  124. var errorMessage = yauzl.validateFileName(fileName);
  125. if (errorMessage != null) throw new Error(errorMessage);
  126. ```
  127. This function is automatically run for each entry, as long as `decodeStrings` is `true`.
  128. See `open()`, `strictFileNames`, and `Event: "entry"` for more information.
  129. ### Class: ZipFile
  130. The constructor for the class is not part of the public API.
  131. Use `open()`, `fromFd()`, `fromBuffer()`, or `fromRandomAccessReader()` instead.
  132. #### Event: "entry"
  133. Callback gets `(entry)`, which is an `Entry`.
  134. See `open()` and `readEntry()` for when this event is emitted.
  135. If `decodeStrings` is `true`, entries emitted via this event have already passed file name validation.
  136. See `validateFileName()` and `open()` for more information.
  137. If `validateEntrySizes` is `true` and this entry's `compressionMethod` is `0` (stored without compression),
  138. this entry has already passed entry size validation.
  139. See `open()` for more information.
  140. #### Event: "end"
  141. Emitted after the last `entry` event has been emitted.
  142. See `open()` and `readEntry()` for more info on when this event is emitted.
  143. #### Event: "close"
  144. Emitted after the fd is actually closed.
  145. This is after calling `close()` (or after the `end` event when `autoClose` is `true`),
  146. and after all stream pipelines created from `openReadStream()` have finished reading data from the fd.
  147. If this `ZipFile` was acquired from `fromRandomAccessReader()`,
  148. the "fd" in the previous paragraph refers to the `RandomAccessReader` implemented by the client.
  149. If this `ZipFile` was acquired from `fromBuffer()`, this event is never emitted.
  150. #### Event: "error"
  151. Emitted in the case of errors with reading the zip file.
  152. (Note that other errors can be emitted from the streams created from `openReadStream()` as well.)
  153. After this event has been emitted, no further `entry`, `end`, or `error` events will be emitted,
  154. but the `close` event may still be emitted.
  155. #### readEntry()
  156. Causes this `ZipFile` to emit an `entry` or `end` event (or an `error` event).
  157. This method must only be called when this `ZipFile` was created with the `lazyEntries` option set to `true` (see `open()`).
  158. When this `ZipFile` was created with the `lazyEntries` option set to `true`,
  159. `entry` and `end` events are only ever emitted in response to this method call.
  160. The event that is emitted in response to this method will not be emitted until after this method has returned,
  161. so it is safe to call this method before attaching event listeners.
  162. After calling this method, calling this method again before the response event has been emitted will cause undefined behavior.
  163. Calling this method after the `end` event has been emitted will cause undefined behavior.
  164. Calling this method after calling `close()` will cause undefined behavior.
  165. #### openReadStream(entry, [options], callback)
  166. `entry` must be an `Entry` object from this `ZipFile`.
  167. `callback` gets `(err, readStream)`, where `readStream` is a `Readable Stream` that provides the file data for this entry.
  168. If this zipfile is already closed (see `close()`), the `callback` will receive an `err`.
  169. `options` may be omitted or `null`, and has the following defaults:
  170. ```js
  171. {
  172. decompress: entry.isCompressed() ? true : null,
  173. decrypt: null,
  174. start: 0, // actually the default is null, see below
  175. end: entry.compressedSize, // actually the default is null, see below
  176. }
  177. ```
  178. If the entry is compressed (with a supported compression method),
  179. and the `decompress` option is `true` (or omitted),
  180. the read stream provides the decompressed data.
  181. Omitting the `decompress` option is what most clients should do.
  182. The `decompress` option must be `null` (or omitted) when the entry is not compressed (see `isCompressed()`),
  183. and either `true` (or omitted) or `false` when the entry is compressed.
  184. Specifying `decompress: false` for a compressed entry causes the read stream
  185. to provide the raw compressed file data without going through a zlib inflate transform.
  186. If the entry is encrypted (see `isEncrypted()`), clients may want to avoid calling `openReadStream()` on the entry entirely.
  187. Alternatively, clients may call `openReadStream()` for encrypted entries and specify `decrypt: false`.
  188. If the entry is also compressed, clients must *also* specify `decompress: false`.
  189. Specifying `decrypt: false` for an encrypted entry causes the read stream to provide the raw, still-encrypted file data.
  190. (This data includes the 12-byte header described in the spec.)
  191. The `decrypt` option must be `null` (or omitted) for non-encrypted entries, and `false` for encrypted entries.
  192. Omitting the `decrypt` option (or specifying it as `null`) for an encrypted entry
  193. will result in the `callback` receiving an `err`.
  194. This default behavior is so that clients not accounting for encrypted files aren't surprised by bogus file data.
  195. The `start` (inclusive) and `end` (exclusive) options are byte offsets into this entry's file data,
  196. and can be used to obtain part of an entry's file data rather than the whole thing.
  197. If either of these options are specified and non-`null`,
  198. then the above options must be used to obain the file's raw data.
  199. Speficying `{start: 0, end: entry.compressedSize}` will result in the complete file,
  200. which is effectively the default values for these options,
  201. but note that unlike omitting the options, when you specify `start` or `end` as any non-`null` value,
  202. the above requirement is still enforced that you must also pass the appropriate options to get the file's raw data.
  203. It's possible for the `readStream` provided to the `callback` to emit errors for several reasons.
  204. For example, if zlib cannot decompress the data, the zlib error will be emitted from the `readStream`.
  205. Two more error cases (when `validateEntrySizes` is `true`) are if the decompressed data has too many
  206. or too few actual bytes compared to the reported byte count from the entry's `uncompressedSize` field.
  207. yauzl notices this false information and emits an error from the `readStream`
  208. after some number of bytes have already been piped through the stream.
  209. This check allows clients to trust the `uncompressedSize` field in `Entry` objects.
  210. Guarding against [zip bomb](http://en.wikipedia.org/wiki/Zip_bomb) attacks can be accomplished by
  211. doing some heuristic checks on the size metadata and then watching out for the above errors.
  212. Such heuristics are outside the scope of this library,
  213. but enforcing the `uncompressedSize` is implemented here as a security feature.
  214. It is possible to destroy the `readStream` before it has piped all of its data.
  215. To do this, call `readStream.destroy()`.
  216. You must `unpipe()` the `readStream` from any destination before calling `readStream.destroy()`.
  217. If this zipfile was created using `fromRandomAccessReader()`, the `RandomAccessReader` implementation
  218. must provide readable streams that implement a `.destroy()` method (see `randomAccessReader._readStreamForRange()`)
  219. in order for calls to `readStream.destroy()` to work in this context.
  220. #### close()
  221. Causes all future calls to `openReadStream()` to fail,
  222. and closes the fd, if any, after all streams created by `openReadStream()` have emitted their `end` events.
  223. If the `autoClose` option is set to `true` (see `open()`),
  224. this function will be called automatically effectively in response to this object's `end` event.
  225. If the `lazyEntries` option is set to `false` (see `open()`) and this object's `end` event has not been emitted yet,
  226. this function causes undefined behavior.
  227. If the `lazyEntries` option is set to `true`,
  228. you can call this function instead of calling `readEntry()` to abort reading the entries of a zipfile.
  229. It is safe to call this function multiple times; after the first call, successive calls have no effect.
  230. This includes situations where the `autoClose` option effectively calls this function for you.
  231. If `close()` is never called, then the zipfile is "kept open".
  232. For zipfiles created with `fromFd()`, this will leave the `fd` open, which may be desirable.
  233. For zipfiles created with `open()`, this will leave the underlying `fd` open, thereby "leaking" it, which is probably undesirable.
  234. For zipfiles created with `fromRandomAccessReader()`, the reader's `close()` method will never be called.
  235. For zipfiles created with `fromBuffer()`, the `close()` function has no effect whether called or not.
  236. Regardless of how this `ZipFile` was created, there are no resources other than those listed above that require cleanup from this function.
  237. This means it may be desirable to never call `close()` in some usecases.
  238. #### isOpen
  239. `Boolean`. `true` until `close()` is called; then it's `false`.
  240. #### entryCount
  241. `Number`. Total number of central directory records.
  242. #### comment
  243. `String`. Always decoded with `CP437` per the spec.
  244. If `decodeStrings` is `false` (see `open()`), this field is the undecoded `Buffer` instead of a decoded `String`.
  245. ### Class: Entry
  246. Objects of this class represent Central Directory Records.
  247. Refer to the zipfile specification for more details about these fields.
  248. These fields are of type `Number`:
  249. * `versionMadeBy`
  250. * `versionNeededToExtract`
  251. * `generalPurposeBitFlag`
  252. * `compressionMethod`
  253. * `lastModFileTime` (MS-DOS format, see `getLastModDateTime`)
  254. * `lastModFileDate` (MS-DOS format, see `getLastModDateTime`)
  255. * `crc32`
  256. * `compressedSize`
  257. * `uncompressedSize`
  258. * `fileNameLength` (bytes)
  259. * `extraFieldLength` (bytes)
  260. * `fileCommentLength` (bytes)
  261. * `internalFileAttributes`
  262. * `externalFileAttributes`
  263. * `relativeOffsetOfLocalHeader`
  264. #### fileName
  265. `String`.
  266. Following the spec, the bytes for the file name are decoded with
  267. `UTF-8` if `generalPurposeBitFlag & 0x800`, otherwise with `CP437`.
  268. Alternatively, this field may be populated from the Info-ZIP Unicode Path Extra Field
  269. (see `extraFields`).
  270. This field is automatically validated by `validateFileName()` before yauzl emits an "entry" event.
  271. If this field would contain unsafe characters, yauzl emits an error instead of an entry.
  272. If `decodeStrings` is `false` (see `open()`), this field is the undecoded `Buffer` instead of a decoded `String`.
  273. Therefore, `generalPurposeBitFlag` and any Info-ZIP Unicode Path Extra Field are ignored.
  274. Furthermore, no automatic file name validation is performed for this file name.
  275. #### extraFields
  276. `Array` with each entry in the form `{id: id, data: data}`,
  277. where `id` is a `Number` and `data` is a `Buffer`.
  278. This library looks for and reads the ZIP64 Extended Information Extra Field (0x0001)
  279. in order to support ZIP64 format zip files.
  280. This library also looks for and reads the Info-ZIP Unicode Path Extra Field (0x7075)
  281. in order to support some zipfiles that use it instead of General Purpose Bit 11
  282. to convey `UTF-8` file names.
  283. When the field is identified and verified to be reliable (see the zipfile spec),
  284. the the file name in this field is stored in the `fileName` property,
  285. and the file name in the central directory record for this entry is ignored.
  286. Note that when `decodeStrings` is false, all Info-ZIP Unicode Path Extra Fields are ignored.
  287. None of the other fields are considered significant by this library.
  288. Fields that this library reads are left unalterned in the `extraFields` array.
  289. #### fileComment
  290. `String` decoded with the charset indicated by `generalPurposeBitFlag & 0x800` as with the `fileName`.
  291. (The Info-ZIP Unicode Path Extra Field has no effect on the charset used for this field.)
  292. If `decodeStrings` is `false` (see `open()`), this field is the undecoded `Buffer` instead of a decoded `String`.
  293. Prior to yauzl version 2.7.0, this field was erroneously documented as `comment` instead of `fileComment`.
  294. For compatibility with any code that uses the field name `comment`,
  295. yauzl creates an alias field named `comment` which is identical to `fileComment`.
  296. #### getLastModDate()
  297. Effectively implemented as:
  298. ```js
  299. return dosDateTimeToDate(this.lastModFileDate, this.lastModFileTime);
  300. ```
  301. #### isEncrypted()
  302. Returns is this entry encrypted with "Traditional Encryption".
  303. Effectively implemented as:
  304. ```js
  305. return (this.generalPurposeBitFlag & 0x1) !== 0;
  306. ```
  307. See `openReadStream()` for the implications of this value.
  308. Note that "Strong Encryption" is not supported, and will result in an `"error"` event emitted from the `ZipFile`.
  309. #### isCompressed()
  310. Effectively implemented as:
  311. ```js
  312. return this.compressionMethod === 8;
  313. ```
  314. See `openReadStream()` for the implications of this value.
  315. ### Class: RandomAccessReader
  316. This class is meant to be subclassed by clients and instantiated for the `fromRandomAccessReader()` function.
  317. An example implementation can be found in `test/test.js`.
  318. #### randomAccessReader._readStreamForRange(start, end)
  319. Subclasses *must* implement this method.
  320. `start` and `end` are Numbers and indicate byte offsets from the start of the file.
  321. `end` is exclusive, so `_readStreamForRange(0x1000, 0x2000)` would indicate to read `0x1000` bytes.
  322. `end - start` will always be at least `1`.
  323. This method should return a readable stream which will be `pipe()`ed into another stream.
  324. It is expected that the readable stream will provide data in several chunks if necessary.
  325. If the readable stream provides too many or too few bytes, an error will be emitted.
  326. (Note that `validateEntrySizes` has no effect on this check,
  327. because this is a low-level API that should behave correctly regardless of the contents of the file.)
  328. Any errors emitted on the readable stream will be handled and re-emitted on the client-visible stream
  329. (returned from `zipfile.openReadStream()`) or provided as the `err` argument to the appropriate callback
  330. (for example, for `fromRandomAccessReader()`).
  331. The returned stream *must* implement a method `.destroy()`
  332. if you call `readStream.destroy()` on streams you get from `openReadStream()`.
  333. If you never call `readStream.destroy()`, then streams returned from this method do not need to implement a method `.destroy()`.
  334. `.destroy()` should abort any streaming that is in progress and clean up any associated resources.
  335. `.destroy()` will only be called after the stream has been `unpipe()`d from its destination.
  336. Note that the stream returned from this method might not be the same object that is provided by `openReadStream()`.
  337. The stream returned from this method might be `pipe()`d through one or more filter streams (for example, a zlib inflate stream).
  338. #### randomAccessReader.read(buffer, offset, length, position, callback)
  339. Subclasses may implement this method.
  340. The default implementation uses `createReadStream()` to fill the `buffer`.
  341. This method should behave like `fs.read()`.
  342. #### randomAccessReader.close(callback)
  343. Subclasses may implement this method.
  344. The default implementation is effectively `setImmediate(callback);`.
  345. `callback` takes parameters `(err)`.
  346. This method is called once the all streams returned from `_readStreamForRange()` have ended,
  347. and no more `_readStreamForRange()` or `read()` requests will be issued to this object.
  348. ## How to Avoid Crashing
  349. When a malformed zipfile is encountered, the default behavior is to crash (throw an exception).
  350. If you want to handle errors more gracefully than this,
  351. be sure to do the following:
  352. * Provide `callback` parameters where they are allowed, and check the `err` parameter.
  353. * Attach a listener for the `error` event on any `ZipFile` object you get from `open()`, `fromFd()`, `fromBuffer()`, or `fromRandomAccessReader()`.
  354. * Attach a listener for the `error` event on any stream you get from `openReadStream()`.
  355. Minor version updates to yauzl will not add any additional requirements to this list.
  356. ## Limitations
  357. ### No Streaming Unzip API
  358. Due to the design of the .zip file format, it's impossible to interpret a .zip file from start to finish
  359. (such as from a readable stream) without sacrificing correctness.
  360. The Central Directory, which is the authority on the contents of the .zip file, is at the end of a .zip file, not the beginning.
  361. A streaming API would need to either buffer the entire .zip file to get to the Central Directory before interpreting anything
  362. (defeating the purpose of a streaming interface), or rely on the Local File Headers which are interspersed through the .zip file.
  363. However, the Local File Headers are explicitly denounced in the spec as being unreliable copies of the Central Directory,
  364. so trusting them would be a violation of the spec.
  365. Any library that offers a streaming unzip API must make one of the above two compromises,
  366. which makes the library either dishonest or nonconformant (usually the latter).
  367. This library insists on correctness and adherence to the spec, and so does not offer a streaming API.
  368. Here is a way to create a spec-conformant .zip file using the `zip` command line program (Info-ZIP)
  369. available in most unix-like environments, that is (nearly) impossible to parse correctly with a streaming parser:
  370. ```
  371. $ echo -ne '\x50\x4b\x07\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' > file.txt
  372. $ zip -q0 - file.txt | cat > out.zip
  373. ```
  374. This .zip file contains a single file entry that uses General Purpose Bit 3,
  375. which means the Local File Header doesn't know the size of the file.
  376. Any streaming parser that encounters this situation will either immediately fail,
  377. or attempt to search for the Data Descriptor after the file's contents.
  378. The file's contents is a sequence of 16-bytes crafted to exactly mimic a valid Data Descriptor for an empty file,
  379. which will fool any parser that gets this far into thinking that the file is empty rather than containing 16-bytes.
  380. What follows the file's real contents is the file's real Data Descriptor,
  381. which will likely cause some kind of signature mismatch error for a streaming parser (if one hasn't occurred already).
  382. By using General Purpose Bit 3 (and compression method 0),
  383. it's possible to create arbitrarily ambiguous .zip files that
  384. distract parsers with file contents that contain apparently valid .zip file metadata.
  385. ### Limitted ZIP64 Support
  386. For ZIP64, only zip files smaller than `8PiB` are supported,
  387. not the full `16EiB` range that a 64-bit integer should be able to index.
  388. This is due to the JavaScript Number type being an IEEE 754 double precision float.
  389. The Node.js `fs` module probably has this same limitation.
  390. ### ZIP64 Extensible Data Sector Is Ignored
  391. The spec does not allow zip file creators to put arbitrary data here,
  392. but rather reserves its use for PKWARE and mentions something about Z390.
  393. This doesn't seem useful to expose in this library, so it is ignored.
  394. ### No Multi-Disk Archive Support
  395. This library does not support multi-disk zip files.
  396. The multi-disk fields in the zipfile spec were intended for a zip file to span multiple floppy disks,
  397. which probably never happens now.
  398. If the "number of this disk" field in the End of Central Directory Record is not `0`,
  399. the `open()`, `fromFd()`, `fromBuffer()`, or `fromRandomAccessReader()` `callback` will receive an `err`.
  400. By extension the following zip file fields are ignored by this library and not provided to clients:
  401. * Disk where central directory starts
  402. * Number of central directory records on this disk
  403. * Disk number where file starts
  404. ### Limited Encryption Handling
  405. You can detect when a file entry is encrypted with "Traditional Encryption" via `isEncrypted()`,
  406. but yauzl will not help you decrypt it.
  407. See `openReadStream()`.
  408. If a zip file contains file entries encrypted with "Strong Encryption", yauzl emits an error.
  409. If the central directory is encrypted or compressed, yauzl emits an error.
  410. ### Local File Headers Are Ignored
  411. Many unzip libraries mistakenly read the Local File Header data in zip files.
  412. This data is officially defined to be redundant with the Central Directory information,
  413. and is not to be trusted.
  414. Aside from checking the signature, yauzl ignores the content of the Local File Header.
  415. ### No CRC-32 Checking
  416. This library provides the `crc32` field of `Entry` objects read from the Central Directory.
  417. However, this field is not used for anything in this library.
  418. ### versionNeededToExtract Is Ignored
  419. The field `versionNeededToExtract` is ignored,
  420. because this library doesn't support the complete zip file spec at any version,
  421. ### No Support For Obscure Compression Methods
  422. Regarding the `compressionMethod` field of `Entry` objects,
  423. only method `0` (stored with no compression)
  424. and method `8` (deflated) are supported.
  425. Any of the other 15 official methods will cause the `openReadStream()` `callback` to receive an `err`.
  426. ### Data Descriptors Are Ignored
  427. There may or may not be Data Descriptor sections in a zip file.
  428. This library provides no support for finding or interpreting them.
  429. ### Archive Extra Data Record Is Ignored
  430. There may or may not be an Archive Extra Data Record section in a zip file.
  431. This library provides no support for finding or interpreting it.
  432. ### No Language Encoding Flag Support
  433. Zip files officially support charset encodings other than CP437 and UTF-8,
  434. but the zip file spec does not specify how it works.
  435. This library makes no attempt to interpret the Language Encoding Flag.
  436. ## Change History
  437. * 2.10.0
  438. * Added support for non-conformant zipfiles created by Microsoft, and added option `strictFileNames` to disable the workaround. [issue #66](https://github.com/thejoshwolfe/yauzl/issues/66), [issue #88](https://github.com/thejoshwolfe/yauzl/issues/88)
  439. * 2.9.2
  440. * Removed `tools/hexdump-zip.js` and `tools/hex2bin.js`. Those tools are now located here: [thejoshwolfe/hexdump-zip](https://github.com/thejoshwolfe/hexdump-zip) and [thejoshwolfe/hex2bin](https://github.com/thejoshwolfe/hex2bin)
  441. * Worked around performance problem with zlib when using `fromBuffer()` and `readStream.destroy()` for large compressed files. [issue #87](https://github.com/thejoshwolfe/yauzl/issues/87)
  442. * 2.9.1
  443. * Removed `console.log()` accidentally introduced in 2.9.0. [issue #64](https://github.com/thejoshwolfe/yauzl/issues/64)
  444. * 2.9.0
  445. * Throw an exception if `readEntry()` is called without `lazyEntries:true`. Previously this caused undefined behavior. [issue #63](https://github.com/thejoshwolfe/yauzl/issues/63)
  446. * 2.8.0
  447. * Added option `validateEntrySizes`. [issue #53](https://github.com/thejoshwolfe/yauzl/issues/53)
  448. * Added `examples/promises.js`
  449. * Added ability to read raw file data via `decompress` and `decrypt` options. [issue #11](https://github.com/thejoshwolfe/yauzl/issues/11), [issue #38](https://github.com/thejoshwolfe/yauzl/issues/38), [pull #39](https://github.com/thejoshwolfe/yauzl/pull/39)
  450. * Added `start` and `end` options to `openReadStream()`. [issue #38](https://github.com/thejoshwolfe/yauzl/issues/38)
  451. * 2.7.0
  452. * Added option `decodeStrings`. [issue #42](https://github.com/thejoshwolfe/yauzl/issues/42)
  453. * Fixed documentation for `entry.fileComment` and added compatibility alias. [issue #47](https://github.com/thejoshwolfe/yauzl/issues/47)
  454. * 2.6.0
  455. * Support Info-ZIP Unicode Path Extra Field, used by WinRAR for Chinese file names. [issue #33](https://github.com/thejoshwolfe/yauzl/issues/33)
  456. * 2.5.0
  457. * Ignore malformed Extra Field that is common in Android .apk files. [issue #31](https://github.com/thejoshwolfe/yauzl/issues/31)
  458. * 2.4.3
  459. * Fix crash when parsing malformed Extra Field buffers. [issue #31](https://github.com/thejoshwolfe/yauzl/issues/31)
  460. * 2.4.2
  461. * Remove .npmignore and .travis.yml from npm package.
  462. * 2.4.1
  463. * Fix error handling.
  464. * 2.4.0
  465. * Add ZIP64 support. [issue #6](https://github.com/thejoshwolfe/yauzl/issues/6)
  466. * Add `lazyEntries` option. [issue #22](https://github.com/thejoshwolfe/yauzl/issues/22)
  467. * Add `readStream.destroy()` method. [issue #26](https://github.com/thejoshwolfe/yauzl/issues/26)
  468. * Add `fromRandomAccessReader()`. [issue #14](https://github.com/thejoshwolfe/yauzl/issues/14)
  469. * Add `examples/unzip.js`.
  470. * 2.3.1
  471. * Documentation updates.
  472. * 2.3.0
  473. * Check that `uncompressedSize` is correct, or else emit an error. [issue #13](https://github.com/thejoshwolfe/yauzl/issues/13)
  474. * 2.2.1
  475. * Update dependencies.
  476. * 2.2.0
  477. * Update dependencies.
  478. * 2.1.0
  479. * Remove dependency on `iconv`.
  480. * 2.0.3
  481. * Fix crash when trying to read a 0-byte file.
  482. * 2.0.2
  483. * Fix event behavior after errors.
  484. * 2.0.1
  485. * Fix bug with using `iconv`.
  486. * 2.0.0
  487. * Initial release.