版博士V2.0程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

README.md 5.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # Container File Blobs
  2. Pure JS implementation of various container file formats, including ZIP and CFB.
  3. [![Build Status](https://travis-ci.org/SheetJS/js-cfb.svg?branch=master)](https://travis-ci.org/SheetJS/js-cfb)
  4. [![Coverage Status](http://img.shields.io/coveralls/SheetJS/js-cfb/master.svg)](https://coveralls.io/r/SheetJS/js-cfb?branch=master)
  5. [![Dependencies Status](https://david-dm.org/sheetjs/js-cfb/status.svg)](https://david-dm.org/sheetjs/js-cfb)
  6. [![NPM Downloads](https://img.shields.io/npm/dt/cfb.svg)](https://npmjs.org/package/cfb)
  7. [![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-cfb?pixel)](https://github.com/SheetJS/js-cfb)
  8. ## Installation
  9. In the browser:
  10. ```html
  11. <script src="dist/cfb.min.js" type="text/javascript"></script>
  12. ```
  13. With [npm](https://www.npmjs.org/package/cfb):
  14. ```bash
  15. $ npm install cfb
  16. ```
  17. The `xlscfb.js` file is designed to be embedded in [js-xlsx](http://git.io/xlsx)
  18. ## Library Usage
  19. In node:
  20. ```js
  21. var CFB = require('cfb');
  22. ```
  23. For example, to get the Workbook content from an Excel 2003 XLS file:
  24. ```js
  25. var cfb = CFB.read(filename, {type: 'file'});
  26. var workbook = CFB.find(cfb, 'Workbook');
  27. var data = workbook.content;
  28. ```
  29. ## Command-Line Utility Usage
  30. The [`cfb-cli`](https://www.npmjs.com/package/cfb-cli) module ships with a CLI
  31. tool for manipulating and inspecting supported files.
  32. ## JS API
  33. TypeScript definitions are maintained in `types/index.d.ts`.
  34. The CFB object exposes the following methods and properties:
  35. `CFB.parse(blob)` takes a nodejs Buffer or an array of bytes and returns an
  36. parsed representation of the data.
  37. `CFB.read(blob, opts)` wraps `parse`.
  38. `CFB.find(cfb, path)` performs a case-insensitive match for the path (or file
  39. name, if there are no slashes) and returns an entry object or null if not found.
  40. `CFB.write(cfb, opts)` generates a file based on the container.
  41. `CFB.writeFile(cfb, filename, opts)` creates a file with the specified name.
  42. ### Parse Options
  43. `CFB.read` takes an options argument. `opts.type` controls the behavior:
  44. | `type` | expected input |
  45. |------------|:----------------------------------------------------------------|
  46. | `"base64"` | string: Base64 encoding of the file |
  47. | `"binary"` | string: binary string (byte `n` is `data.charCodeAt(n)`) |
  48. | `"buffer"` | nodejs Buffer |
  49. | `"file"` | string: path of file that will be read (nodejs only) |
  50. | (default) | buffer or array of 8-bit unsigned int (byte `n` is `data[n]`) |
  51. ### Write Options
  52. `CFB.write` and `CFB.writeFile` take options argument.
  53. `opts.type` controls the behavior:
  54. | `type` | output |
  55. |------------|:----------------------------------------------------------------|
  56. | `"base64"` | string: Base64 encoding of the file |
  57. | `"binary"` | string: binary string (byte `n` is `data.charCodeAt(n)`) |
  58. | `"buffer"` | nodejs Buffer |
  59. | `"file"` | string: path of file that will be created (nodejs only) |
  60. | (default) | buffer if available, array of 8-bit unsigned int otherwise |
  61. `opts.fileType` controls the output file type:
  62. | `fileType` | output |
  63. |:-------------------|:------------------------|
  64. | `'cfb'` (default) | CFB container |
  65. | `'zip'` | ZIP file |
  66. | `'mad'` | MIME aggregate document |
  67. `opts.compression` enables DEFLATE compression for ZIP file type.
  68. ## Utility Functions
  69. The utility functions are available in the `CFB.utils` object. Functions that
  70. accept a `name` argument strictly deal with absolute file names:
  71. - `.cfb_new(?opts)` creates a new container object.
  72. - `.cfb_add(cfb, name, ?content, ?opts)` adds a new file to the `cfb`.
  73. Set the option `{unsafe:true}` to skip existence checks (for bulk additions)
  74. - `.cfb_del(cfb, name)` deletes the specified file
  75. - `.cfb_mov(cfb, old_name, new_name)` moves the old file to new path and name
  76. - `.use_zlib(require("zlib"))` loads a nodejs `zlib` instance.
  77. By default, the library uses a pure JS inflate/deflate implementation. NodeJS
  78. `zlib.InflateRaw` exposes the number of bytes read in versions after `8.11.0`.
  79. If a supplied `zlib` does not support the required features, a warning will be
  80. displayed in the console and the pure JS fallback will be used.
  81. ## Container Object Description
  82. The objects returned by `parse` and `read` have the following properties:
  83. - `.FullPaths` is an array of the names of all of the streams (files) and
  84. storages (directories) in the container. The paths are properly prefixed from
  85. the root entry (so the entries are unique)
  86. - `.FileIndex` is an array, in the same order as `.FullPaths`, whose values are
  87. objects following the schema:
  88. ```typescript
  89. interface CFBEntry {
  90. name: string; /** Case-sensitive internal name */
  91. type: number; /** 1 = dir, 2 = file, 5 = root ; see [MS-CFB] 2.6.1 */
  92. content: Buffer | number[] | Uint8Array; /** Raw Content */
  93. ct?: Date; /** Creation Time */
  94. mt?: Date; /** Modification Time */
  95. ctype?: String; /** Content-Type (for MAD) */
  96. }
  97. ```
  98. ## License
  99. Please consult the attached LICENSE file for details. All rights not explicitly
  100. granted by the Apache 2.0 License are reserved by the Original Author.
  101. ## References
  102. - `MS-CFB`: Compound File Binary File Format
  103. - ZIP `APPNOTE.TXT`: .ZIP File Format Specification
  104. - RFC1951: https://www.ietf.org/rfc/rfc1951.txt
  105. - RFC2045: https://www.ietf.org/rfc/rfc2045.txt
  106. - RFC2557: https://www.ietf.org/rfc/rfc2557.txt