HTTP Downloads demo refresh

This commit is contained in:
SheetJS 2024-06-22 04:16:02 -04:00
parent 44adb843c1
commit 7d749963f4
6 changed files with 135 additions and 30 deletions

@ -16,6 +16,7 @@ const EngineData = () => {
<div dangerouslySetInnerHTML={{__html: engines}}/>
<p>The following bindings have been tested:</p>
<div dangerouslySetInnerHTML={{__html: binding}}/>
<p>Asterisks () in the Windows columns mark tests that were run in Windows Subsystem for Linux (WSL)</p>
</> );
};
export default EngineData;

@ -182,8 +182,8 @@
<Cell><Data ss:Type="String">C</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String"></Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String"></Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String"></Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String"></Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
</Row>
@ -212,7 +212,7 @@
<Cell><Data ss:Type="String">C#</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"/>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"/>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
@ -322,7 +322,7 @@
<Cell><Data ss:Type="String">Java</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"/>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"/>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>
<Cell ss:StyleID="s16"><Data ss:Type="String">✔</Data></Cell>

@ -40,7 +40,7 @@ This browser demo was tested in the following environments:
| Browser | Date |
|:------------|:-----------|
| Chrome 119 | 2024-01-06 |
| Chrome 126 | 2024-06-21 |
| Safari 17.4 | 2024-06-20 |
:::

@ -11,10 +11,19 @@ pagination_next: demos/net/upload/index
import current from '/version.js';
import CodeBlock from '@theme/CodeBlock';
`XMLHttpRequest` and `fetch` browser APIs enable binary data transfer between
web browser clients and web servers. Since this library works in web browsers,
server conversion work can be offloaded to the client! This demo shows a few
common scenarios involving browser APIs and popular wrapper libraries.
[SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing
data from spreadsheets.
A number of JavaScript APIs, including `XMLHttpRequest` and `fetch`, allow
scripts to download spreadsheets for further processing.
This demo uses various APIs and wrapper libraries to download workbooks and pass
raw binary data to SheetJS libraries.
- ["Browser Demos"](#browser-demos) run entirely within the web browser. A test
workbook will be downloaded and parsed in the web browser.
- ["NodeJS Demos"](#nodejs-demos) run in NodeJS and other server-side platforms.
:::info pass
@ -36,7 +45,7 @@ functions functions can send files to clients.
:::
## Downloading Binary Data
## Binary Data
Most interesting spreadsheet files are binary data that contain byte sequences
that represent invalid UTF-8 characters.
@ -374,7 +383,7 @@ The `https` module provides a low-level `get` method for HTTPS GET requests:
```js title="SheetJSHTTPSGet.js"
var https = require("https"), XLSX = require("xlsx");
https.get('https://docs.sheetjs.com/pres.numbers', function(res) {
https.get('https://docs.sheetjs.com/pres.xlsx', function(res) {
var bufs = [];
res.on('data', function(chunk) { bufs.push(chunk); });
res.on('end', function() {
@ -387,15 +396,36 @@ https.get('https://docs.sheetjs.com/pres.numbers', function(res) {
});
```
<details>
<summary><b>Complete Example</b> (click to show)</summary>
:::note Tested Deployments
:::note Tested Environments
This demo was tested in the following environments:
This demo was last tested on 2024 January 15 against NodeJS `20.11.0`
| NodeJS | Date | Workarounds |
|:-----------|:-----------|:-------------------------------|
| `0.10.48` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `0.12.18` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `4.9.1` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `6.17.1` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `8.17.0` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `10.24.1` | 2024-06-21 | |
| `12.22.12` | 2024-06-21 | |
| `14.21.3` | 2024-06-21 | |
| `16.20.2` | 2024-06-21 | |
| `18.20.3` | 2024-06-21 | |
| `20.15.0` | 2024-06-21 | |
| `22.3.0` | 2024-06-21 | |
The `NODE_TLS_REJECT_UNAUTHORIZED` workaround sets the value to `'0'`:
```js title="Legacy NodeJS Certificate has Expired Bypass (prepend to script)"
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
```
:::
<details>
<summary><b>Complete Example</b> (click to show)</summary>
1) Install the [NodeJS module](/docs/getting-started/installation/nodejs)
<CodeBlock language="bash">{`\
@ -412,11 +442,24 @@ node SheetJSHTTPSGet.js
If successful, the script will print CSV contents of the test file.
:::caution pass
For older versions of NodeJS, the script will fail due to a certificate error.
The error can be suppressed by prepending the following line to the script:
```js title="SheetJSHTTPSGet.js (add to top)"
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
```
**It is strongly encouraged to upgrade to a newer NodeJS version!**
:::
</details>
### fetch
:::caution pass
:::info pass
Experimental support for `fetch` was introduced in NodeJS `16.15.0`. It will be
considered stable in NodeJS LTS version `22`.
@ -435,15 +478,21 @@ async function parse_from_url(url) {
}
```
<details>
<summary><b>Complete Example</b> (click to show)</summary>
:::note Tested Deployments
:::note Tested Environments
This demo was tested in the following environments:
This demo was last tested on 2024 January 15 against NodeJS `20.11.0`
| NodeJS | Date |
|:-----------|:-----------|
| `18.20.3` | 2024-06-21 |
| `20.15.0` | 2024-06-21 |
| `22.3.0` | 2024-06-21 |
:::
<details>
<summary><b>Complete Example</b> (click to show)</summary>
1) Install the [NodeJS module](/docs/getting-started/installation/nodejs)
<CodeBlock language="bash">{`\
@ -498,7 +547,7 @@ Setting the option `encoding: null` passes raw buffers:
```js title="SheetJSRequest.js"
var XLSX = require('xlsx'), request = require('request');
var url = 'https://docs.sheetjs.com/pres.numbers';
var url = 'https://docs.sheetjs.com/pres.xlsx';
/* call `request` with the option `encoding: null` */
// highlight-next-line
@ -515,15 +564,36 @@ request(url, {encoding: null}, function(err, res, data) {
});
```
<details>
<summary><b>Complete Example</b> (click to show)</summary>
:::note Tested Deployments
:::note Tested Environments
This demo was tested in the following environments:
This demo was last tested on 2024 January 15 against request `2.88.2`
| NodeJS | Date | Workarounds |
|:-----------|:-----------|:-------------------------------|
| `0.10.48` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `0.12.18` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `4.9.1` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `6.17.1` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `8.17.0` | 2024-06-21 | `NODE_TLS_REJECT_UNAUTHORIZED` |
| `10.24.1` | 2024-06-21 | |
| `12.22.12` | 2024-06-21 | |
| `14.21.3` | 2024-06-21 | |
| `16.20.2` | 2024-06-21 | |
| `18.20.3` | 2024-06-21 | |
| `20.15.0` | 2024-06-21 | |
| `22.3.0` | 2024-06-21 | |
The `NODE_TLS_REJECT_UNAUTHORIZED` workaround sets the value to `'0'`:
```js title="Legacy NodeJS Certificate has Expired Bypass (prepend to script)"
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
```
:::
<details>
<summary><b>Complete Example</b> (click to show)</summary>
1) Install the [NodeJS module](/docs/getting-started/installation/nodejs)
<CodeBlock language="bash">{`\
@ -540,6 +610,19 @@ node SheetJSRequest.js
If successful, the script will print CSV contents of the test file.
:::caution pass
For older versions of NodeJS, the script will fail due to a certificate error.
The error can be suppressed by prepending the following line to the script:
```js title="SheetJSRequest.js (add to top)"
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
```
**It is strongly encouraged to upgrade to a newer NodeJS version!**
:::
</details>
#### axios
@ -558,19 +641,29 @@ async function workbook_dl_axios(url) {
}
```
<details>
<summary><b>Complete Example</b> (click to show)</summary>
:::note Tested Deployments
:::note Tested Environments
This demo was tested in the following environments:
This demo was last tested on 2024 January 15 against Axios `1.6.5`
| NodeJS | Axios | Date |
|:-----------|:-------|:-----------|
| `10.24.1` | 0.28.1 | 2024-06-21 |
| `12.22.12` | 1.7.2 | 2024-06-21 |
| `14.21.3` | 1.7.2 | 2024-06-21 |
| `16.20.2` | 1.7.2 | 2024-06-21 |
| `18.20.3` | 1.7.2 | 2024-06-21 |
| `20.15.0` | 1.7.2 | 2024-06-21 |
| `22.3.0` | 1.7.2 | 2024-06-21 |
:::
<details>
<summary><b>Complete Example</b> (click to show)</summary>
1) Install the [NodeJS module](/docs/getting-started/installation/nodejs)
<CodeBlock language="bash">{`\
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz axios@1.6.5`}
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz axios@1.7.2`}
</CodeBlock>
2) Save the following to `SheetJSAxios.js`:

@ -992,6 +992,7 @@ This demo was last tested in the following deployments:
|:-------------|:--------------|:--------|:----------|:-----------|
| `darwin-x64` | `12.6.228.13` | `3.1.3` | `22` | 2024-06-19 |
| `darwin-arm` | `12.6.228.13` | `3.1.3` | `11.0.23` | 2024-06-19 |
| `win10-x64` | `12.6.228.13` | `3.1.3` | `11.0.16` | 2024-06-21 |
| `linux-x64` | `12.6.228.13` | `3.1.3` | `17.0.7` | 2024-06-20 |
| `linux-arm` | `12.6.228.13` | `3.1.3` | `17.0.11` | 2024-06-20 |
@ -1043,6 +1044,10 @@ curl -LO https://repo1.maven.org/maven2/com/caoccao/javet/javet-linux-arm64/3.1.
</TabItem>
<TabItem value="win" label="Windows">
```bash
curl -LO https://repo1.maven.org/maven2/com/caoccao/javet/javet/3.1.3/javet-3.1.3.jar
```
</TabItem>
</Tabs>
@ -1108,6 +1113,11 @@ java -cp ".:javet-linux-arm64-3.1.3.jar" SheetJSJavet pres.xlsx
</TabItem>
<TabItem value="win" label="Windows">
```bash
javac -cp ".;javet-3.1.3.jar" SheetJSJavet.java
java -cp ".;javet-3.1.3.jar" SheetJSJavet pres.xlsx
```
</TabItem>
</Tabs>

@ -178,6 +178,7 @@ This demo was tested in the following deployments:
|:-------------|:---------|:-----------|
| `darwin-x64` | `3.2.7` | 2024-06-15 |
| `darwin-arm` | `3.2.7` | 2024-06-15 |
| `win10-x64` | `3.2.7` | 2024-06-21 |
| `linux-x64` | `3.2.7` | 2024-06-20 |
| `linux-arm` | `3.2.7` | 2024-06-20 |