Skip to content

Commit 045adba

Browse files
committed
parse ZIP64 length (fixes #2766 h/t @silvialeung)
1 parent 199373e commit 045adba

File tree

134 files changed

+65
-4907
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+65
-4907
lines changed

bits/18_cfb.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,15 @@ function parse_extra_field(blob/*:CFBlob*/)/*:any*/ {
211211
if(flags & 4) p.ctime = blob.read_shift(4);
212212
}
213213
if(p.mtime) p.mt = new Date(p.mtime*1000);
214-
}
215-
break;
214+
} break;
215+
/* ZIP64 Extended Information Field */
216+
case 0x0001: {
217+
var sz1 = blob.read_shift(4), sz2 = blob.read_shift(4);
218+
p.usz = (sz2 * Math.pow(2,32) + sz1);
219+
sz1 = blob.read_shift(4); sz2 = blob.read_shift(4);
220+
p.csz = (sz2 * Math.pow(2,32) + sz1);
221+
// NOTE: volume fields are skipped
222+
} break;
216223
}
217224
blob.l = tgt;
218225
o[type] = p;
@@ -1401,6 +1408,11 @@ function parse_zip(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/
14011408

14021409
var L = blob.l;
14031410
blob.l = offset + 4;
1411+
/* ZIP64 lengths */
1412+
if(EF && EF[0x0001]) {
1413+
if((EF[0x0001]||{}).usz) usz = EF[0x0001].usz;
1414+
if((EF[0x0001]||{}).csz) csz = EF[0x0001].csz;
1415+
}
14041416
parse_local_file(blob, csz, usz, o, EF);
14051417
blob.l = L;
14061418
}
@@ -1430,7 +1442,13 @@ function parse_local_file(blob/*:CFBlob*/, csz/*:number*/, usz/*:number*/, o/*:C
14301442
if(efsz) {
14311443
var ef = parse_extra_field(/*::(*/blob.slice(blob.l, blob.l + efsz)/*:: :any)*/);
14321444
if((ef[0x5455]||{}).mt) date = ef[0x5455].mt;
1433-
if(((EF||{})[0x5455]||{}).mt) date = EF[0x5455].mt;
1445+
if((ef[0x0001]||{}).usz) _usz = ef[0x0001].usz;
1446+
if((ef[0x0001]||{}).csz) _csz = ef[0x0001].csz;
1447+
if(EF) {
1448+
if((EF[0x5455]||{}).mt) date = EF[0x5455].mt;
1449+
if((EF[0x0001]||{}).usz) _usz = ef[0x0001].usz;
1450+
if((EF[0x0001]||{}).csz) _csz = ef[0x0001].csz;
1451+
}
14341452
}
14351453
blob.l += efsz;
14361454

demos/README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ can be installed with Bash on Windows or with `cygwin`.
2626
- [`IndexedDB`](https://docs.sheetjs.com/docs/demos/database#indexeddb)
2727

2828
**Frameworks**
29+
- [`Angular 2+ and Ionic`](https://docs.sheetjs.com/docs/demos/angular)
30+
- [`React`](https://docs.sheetjs.com/docs/demos/react)
31+
- [`VueJS`](https://docs.sheetjs.com/docs/demos/vue)
2932
- [`Angular.JS`](https://docs.sheetjs.com/docs/demos/legacy#angularjs)
30-
- [`Angular 2+ and Ionic`](angular2/)
3133
- [`Knockout`](https://docs.sheetjs.com/docs/demos/legacy#knockoutjs)
32-
- [`React and NextJS`](react/)
33-
- [`VueJS`](vue/)
3434

3535
**Front-End UI Components**
3636
- [`canvas-datagrid`](https://docs.sheetjs.com/docs/demos/grid#canvas-datagrid)
37-
- [`x-spreadsheet`](xspreadsheet/)
38-
- [`react-data-grid`](react/modify/)
39-
- [`vue3-table-light`](vue/modify/)
37+
- [`x-spreadsheet`](https://docs.sheetjs.com/docs/demos/grid#x-spreadsheet)
38+
- [`react-data-grid`](https://docs.sheetjs.com/docs/demos/grid#react-data-grid)
39+
- [`vue3-table-lite`](https://docs.sheetjs.com/docs/demos/grid#vue3-table-lite)
4040
- [`angular-ui-grid`](https://docs.sheetjs.com/docs/demos/grid#angular-ui-grid)
4141

4242
**Platforms and Integrations**
4343
- [`Command-Line Tools`](https://docs.sheetjs.com/docs/demos/cli)
4444
- [`iOS and Android Mobile Applications`](https://docs.sheetjs.com/docs/demos/mobile)
45-
- [`NodeJS Server-Side Processing`](server/)
45+
- [`NodeJS Server-Side Processing`](https://docs.sheetjs.com/docs/demos/server#nodejs)
4646
- [`Content Management and Static Sites`](https://docs.sheetjs.com/docs/demos/content)
4747
- [`Electron`](https://docs.sheetjs.com/docs/demos/desktop#electron)
4848
- [`NW.js`](https://docs.sheetjs.com/docs/demos/desktop#nwjs)
@@ -54,8 +54,9 @@ can be installed with Bash on Windows or with `cygwin`.
5454
- [`SalesForce Lightning Web Components`](https://docs.sheetjs.com/docs/demos/salesforce)
5555
- [`Excel JavaScript API`](https://docs.sheetjs.com/docs/demos/excel)
5656
- [`Headless Automation`](https://docs.sheetjs.com/docs/demos/headless)
57-
- [`Swift JSC and Other JavaScript Engines`](https://docs.sheetjs.com/docs/demos/engines)
58-
- [`"serverless" functions`](function/)
57+
- [`Other JavaScript Engines`](https://docs.sheetjs.com/docs/demos/engines)
58+
- [`Azure Functions and Storage`](https://docs.sheetjs.com/docs/demos/azure)
59+
- [`Amazon Web Services`](https://docs.sheetjs.com/docs/demos/aws)
5960
- [`Databases and Structured Data Stores`](https://docs.sheetjs.com/docs/demos/database)
6061
- [`NoSQL and Unstructured Data Stores`](https://docs.sheetjs.com/docs/demos/nosql)
6162
- [`Legacy Internet Explorer`](https://docs.sheetjs.com/docs/demos/legacy#internet-explorer)

demos/angular2/.angular-cli.json

Lines changed: 0 additions & 23 deletions
This file was deleted.

demos/angular2/.eslintrc

Lines changed: 0 additions & 6 deletions
This file was deleted.

demos/angular2/.gitattributes

Lines changed: 0 additions & 1 deletion
This file was deleted.

demos/angular2/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

demos/angular2/Makefile

Lines changed: 0 additions & 34 deletions
This file was deleted.

demos/angular2/README.md

Lines changed: 5 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,11 @@
11
# Angular 2+
22

3-
The ESM build can be imported directly from TS code with:
3+
[The new demo](https://docs.sheetjs.com/docs/demos/angular) has an updated
4+
exposition for legacy and modern deployments alike.
45

5-
```typescript
6-
import { read, utils, writeFileXLSX } from 'xlsx';
7-
```
6+
The ecosystem demos were grouped by type in the new demo site:
87

9-
This demo uses an array of arrays (type `Array<Array<any>>`) as the core state.
10-
The component template includes a file input element, a table that updates with
11-
the data, and a button to export the data.
12-
13-
Other scripts in this demo show:
14-
- `ionic` deployment for iOS, android, and browser
15-
- `nativescript` deployment for iOS and android
16-
17-
## Array of Arrays
18-
19-
`Array<Array<any>>` neatly maps to a table with `ngFor`:
20-
21-
```html
22-
<table class="sjs-table">
23-
<tr *ngFor="let row of data">
24-
<td *ngFor="let val of row">
25-
{{val}}
26-
</td>
27-
</tr>
28-
</table>
29-
```
30-
31-
The `aoa_to_sheet` utility function returns a worksheet. Exporting is simple:
32-
33-
```typescript
34-
/* generate worksheet */
35-
const ws: XLSX.WorkSheet = XLSX.utils.aoa_to_sheet(this.data);
36-
37-
/* generate workbook and add the worksheet */
38-
const wb: XLSX.WorkBook = XLSX.utils.book_new();
39-
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
40-
41-
/* save to file */
42-
XLSX.writeFile(wb, 'SheetJS.xlsx');
43-
```
44-
45-
`sheet_to_json` with the option `header:1` makes importing simple:
46-
47-
```typescript
48-
/* <input type="file" (change)="onFileChange($event)" multiple="false" /> */
49-
/* ... (within the component class definition) ... */
50-
onFileChange(evt: any) {
51-
/* wire up file reader */
52-
const target: DataTransfer = <DataTransfer>(evt.target);
53-
if (target.files.length !== 1) throw new Error('Cannot use multiple files');
54-
const reader: FileReader = new FileReader();
55-
reader.onload = (e: any) => {
56-
/* read workbook */
57-
const ab: ArrayBuffer = e.target.result;
58-
const wb: XLSX.WorkBook = XLSX.read(ab);
59-
60-
/* grab first sheet */
61-
const wsname: string = wb.SheetNames[0];
62-
const ws: XLSX.WorkSheet = wb.Sheets[wsname];
63-
64-
/* save data */
65-
this.data = <AOA>(XLSX.utils.sheet_to_json(ws, {header: 1}));
66-
};
67-
reader.readAsArrayBuffer(target.files[0]);
68-
}
69-
```
70-
71-
## Switching between Angular versions
72-
73-
Modules that work with Angular 2 largely work as-is with Angular 4+. Switching
74-
between versions is mostly a matter of installing the correct version of the
75-
core and associated modules. This demo includes `package.json-angular#` files
76-
for every major version of Angular up to 12.
77-
78-
To test a particular Angular version, overwrite `package.json`:
79-
80-
```bash
81-
# switch to Angular 2
82-
$ cp package.json-ng2 package.json
83-
$ npm install
84-
$ ng serve
85-
```
86-
87-
Note: when running the demos, Angular 2 requires Node <= 14. This is due to a
88-
tooling issue with `ng` and does not affect browser use.
89-
90-
## XLSX Symbolic Link
91-
92-
In this tree, `node_modules/xlsx` is a link pointing back to the root. This
93-
enables testing the development version of the library. In order to use this
94-
demo in other applications, add the `xlsx` dependency:
95-
96-
```bash
97-
$ npm install --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
98-
```
99-
100-
## SystemJS Configuration
101-
102-
The default angular-cli configuration requires no additional configuration.
103-
104-
Some deployments use the SystemJS loader, which does require configuration.
105-
[SystemJS](https://docs.sheetjs.com/docs/demos/bundler#systemjs)
106-
demo in the SheetJS CE docs describe the required settings.
107-
108-
## Ionic
109-
110-
<img src="screen.png" width="400px"/>
111-
112-
Reproducing the full project is a little bit tricky. The included `ionic.sh`
113-
script performs the necessary installation steps.
114-
115-
`Array<Array<any>>` neatly maps to a table with `ngFor`:
116-
117-
```html
118-
<ion-grid>
119-
<ion-row *ngFor="let row of data">
120-
<ion-col *ngFor="let val of row">
121-
{{val}}
122-
</ion-col>
123-
</ion-row>
124-
</ion-grid>
125-
```
126-
127-
128-
`@ionic-native/file` reads and writes files on devices. `readAsArrayBuffer`
129-
returns `ArrayBuffer` objects suitable for `array` type, and `array` type can
130-
be converted to blobs that can be exported with `writeFile`:
131-
132-
```typescript
133-
/* read a workbook */
134-
const ab: ArrayBuffer = await this.file.readAsArrayBuffer(url, filename);
135-
const wb: XLSX.WorkBook = XLSX.read(bstr, {type: 'array'});
136-
137-
/* write a workbook */
138-
const wbout: ArrayBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
139-
let blob = new Blob([wbout], {type: 'application/octet-stream'});
140-
this.file.writeFile(url, filename, blob, {replace: true});
141-
```
142-
143-
## NativeScript
144-
145-
[The new demo](https://docs.sheetjs.com/docs/demos/mobile#nativescript)
146-
is updated for NativeScript 8 and uses more idiomatic data patterns.
8+
- [NativeScript](https://docs.sheetjs.com/docs/demos/mobile#nativescript) is now part of "iOS and Android Apps"
9+
- [Ionic](https://docs.sheetjs.com/docs/demos/mobile#ionic) is now part of "iOS and Android Apps"
14710

14811
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

demos/angular2/ionic-app.module.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

demos/angular2/ionic.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)