Skip to content

Commit 026492f

Browse files
committed
merge main
2 parents e4629f4 + 1f77117 commit 026492f

11 files changed

Lines changed: 50 additions & 180 deletions

File tree

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
**/Internal-Documentation/*
1515
*.testjs
1616
*.testts
17-
*__snapshots__/*
17+
*__snapshots__/*

.github/commands/dependencies/install_yarn_deps/action.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ runs:
1919
.yarn/unplugged
2020
.yarn/install-state.gz
2121
.pnp.cjs
22-
key: ${{ runner.os }}-${{ runner.arch }}-yarn-v10-${{ hashFiles('**/yarn.lock', '**/package.json') }}
22+
key: ${{ runner.os }}-${{ runner.arch }}-yarn-v3-${{ hashFiles('**/yarn.lock', '**/package.json') }}
2323
restore-keys: |
24-
${{ runner.os }}-${{ runner.arch }}-yarn-v10-
25-
- uses: nick-fields/retry@v3
26-
if: steps.yarn-cache.outputs.cache-hit != 'true' || inputs.force-yarn-install == 'true'
27-
with:
28-
timeout_minutes: 10
29-
max_attempts: 3
30-
retry_on: error
31-
command: yarn install --immutable
24+
${{ runner.os }}-${{ runner.arch }}-yarn-v3-
25+
- run: yarn install --immutable
26+
name: Install yarn deps
27+
shell: bash

.github/workflows/ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ jobs:
55
build-and-upload-artifacts:
66
runs-on: ubuntu-latest
77
steps:
8-
- uses: actions/checkout@v2
8+
- uses: actions/checkout@v4
99
- uses: ./.github/commands/dependencies/install_yarn_deps
1010
- name: Build
1111
run: yarn build
12-
- uses: actions/upload-artifact@v3
12+
- uses: actions/upload-artifact@v4
1313
with:
1414
name: build-artifact
1515
path: dist/
@@ -21,24 +21,24 @@ jobs:
2121
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
2222
timeout-minutes: 10
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v4
2525
- uses: ./.github/commands/dependencies/install_yarn_deps
2626
- run: yarn test:browserstack
2727

2828
run-depcheck:
2929
runs-on: ubuntu-latest
3030
steps:
31-
- uses: actions/checkout@v2
31+
- uses: actions/checkout@v4
3232
- uses: ./.github/commands/dependencies/install_yarn_deps
3333
- run: yarn depcheck
3434

3535
run-pre-commits:
3636
runs-on: ubuntu-latest
3737
steps:
38-
- uses: actions/checkout@v2
38+
- uses: actions/checkout@v4
3939
with:
4040
fetch-depth: 100 # need the history to do a changed files check below (source, origin)
41-
- uses: actions/setup-python@v2
41+
- uses: actions/setup-python@v5
4242
- uses: ./.github/commands/dependencies/install_yarn_deps
4343
- uses: pre-commit/action@v3.0.0
4444

@@ -53,10 +53,10 @@ jobs:
5353
- run-pre-commits
5454
steps:
5555
- name: Checkout
56-
uses: actions/checkout@v2
56+
uses: actions/checkout@v4
5757
- uses: ./.github/commands/dependencies/install_yarn_deps
5858
- name: Download build artifact
59-
uses: actions/download-artifact@v3
59+
uses: actions/download-artifact@v4
6060
with:
6161
name: build-artifact
6262
path: dist
@@ -78,10 +78,10 @@ jobs:
7878
- run-pre-commits
7979
steps:
8080
- name: Checkout
81-
uses: actions/checkout@v2
81+
uses: actions/checkout@v4
8282
- uses: ./.github/commands/dependencies/install_yarn_deps
8383
- name: Download build artifact
84-
uses: actions/download-artifact@v3
84+
uses: actions/download-artifact@v4
8585
with:
8686
name: build-artifact
8787
path: dist

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"**/.pnp.*": true
3535
},
3636
"editor.codeActionsOnSave": {
37-
"source.fixAll": "explicit"
37+
"source.fixAll": "always"
3838
},
3939
"cSpell.words": [
4040
"allsettled",

README.md

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@
99
- [Examples](#examples)
1010
- [Usage](#usage)
1111
- [Importing Conflux](#importing-conflux)
12-
- [Package Manager](#package-manager)
13-
- [CDN](#cdn)
1412
- [Creating a ZIP](#creating-a-zip)
1513
- [Example using `ReadableStream#pipeThrough`](#example-using-readablestreampipethrough)
1614
- [Example using `writer.write`](#example-using-writerwrite)
1715
- [Incorporating other streams](#incorporating-other-streams)
1816
- [Reading ZIP files](#reading-zip-files)
19-
- [Supporting Firefox](#supporting-firefox)
17+
- [Supporting Legacy Browsers](#supporting-legacy-browsers)
2018
- [License](#license)
2119

2220
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -43,7 +41,7 @@
4341

4442
## Blazing Fast
4543

46-
- ~100 kB import
44+
- ~55 kB import
4745
- Uses streams, minimizing memory overhead
4846

4947
## Compatibility
@@ -64,13 +62,7 @@
6462

6563
### Importing Conflux
6664

67-
#### Package Manager
68-
6965
```sh
70-
# With Yarn
71-
yarn add @transcend-io/conflux
72-
73-
# With NPM
7466
npm install --save @transcend-io/conflux
7567
```
7668

@@ -79,17 +71,6 @@ npm install --save @transcend-io/conflux
7971
import { Reader, Writer } from '@transcend-io/conflux';
8072
```
8173

82-
#### CDN
83-
84-
```html
85-
<script src="https://cdn.jsdelivr.net/npm/@transcend-io/conflux@3"></script>
86-
```
87-
88-
```js
89-
// Reader parses zip files, Writer builds zip files
90-
const { Reader, Writer } = window.conflux;
91-
```
92-
9374
### Creating a ZIP
9475

9576
#### Example using `ReadableStream#pipeThrough`
@@ -98,7 +79,7 @@ const { Reader, Writer } = window.conflux;
9879
import { Writer } from '@transcend-io/conflux';
9980
import streamSaver from 'streamsaver';
10081

101-
const s3 = 'https://s3-us-west-2.amazonaws.com/bencmbrook/';
82+
const s3 = 'https://s3-us-west-2.amazonaws.com/your-bucket/';
10283
const files = ['NYT.txt', 'water.png', 'Earth.jpg'].values();
10384

10485
const myReadable = new ReadableStream({
@@ -165,7 +146,7 @@ const fileStream = streamSaver.createWriteStream('conflux.zip');
165146
});
166147

167148
const imgStream = await fetch(
168-
'https://s3-us-west-2.amazonaws.com/bencmbrook/Earth.jpg',
149+
'https://s3-us-west-2.amazonaws.com/your-bucket/Earth.jpg',
169150
).then((r) => r.body);
170151

171152
writer.write({
@@ -195,64 +176,15 @@ fetch('https://cdn.jsdelivr.net/gh/Stuk/jszip/test/ref/deflate.zip').then(
195176
);
196177
```
197178

198-
### Reading ZIP files from a stream
199-
200-
#### Example using `ReadableStream#pipeThrough`
201-
202-
<!-- prettier-ignore -->
203-
```js
204-
import { StreamReader } from '@transcend-io/conflux';
205-
import streamSaver from 'streamsaver';
206-
207-
// Fetch a ZIP file from a remote source
208-
const zipUrl = '/some-large.zip';
209-
const response = await fetch(zipUrl);
210-
211-
// Extract files with StreamReader (a TransformStream)
212-
response.body
213-
.pipeThrough(new StreamReader())
214-
.pipeTo(
215-
new WritableStream({
216-
// The StreamReader emits each file's name and a stream containing its contents
217-
async write({ name, stream }) {
218-
console.log(`Extracting: ${name}`);
219-
220-
// Save each extracted file, also with streams
221-
const fileStream = stream();
222-
await fileStream
223-
.pipeTo(
224-
streamSaver.createWriteStream(name)
225-
);
226-
},
227-
}),
228-
);
229-
```
230-
231-
## Supporting Firefox
179+
## Supporting Legacy Browsers
232180

233-
Firefox [does not support ReadableStream#pipeThrough](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility), since it does not have `WritableStream` or `TransformStream` support yet. Conflux ponyfills `TransformStream` out of the box in Firefox, but if you're using the `myReadable.pipeThrough` and plan to support Firefox, you'll want to ponyfill `ReadableStream` like so:
181+
Conflux is compatible with all modern browsers since June 2022.
234182

235-
```js
236-
import { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill/ponyfill';
237-
238-
// Support Firefox with a ponyfill on ReadableStream to add .pipeThrough
239-
const ModernReadableStream = window.WritableStream
240-
? window.ReadableStream
241-
: ReadableStreamPonyfill;
242-
243-
const myReadable = new ModernReadableStream({
244-
async pull(controller) {
245-
return controller.enqueue({
246-
name: `/firefox.txt`,
247-
stream: () => new Response.body('Firefox works!'),
248-
});
249-
},
250-
});
183+
If you need to support legacy browsers, you can add polyfills for:
251184

252-
myReadable
253-
.pipeThrough(new Writer()) // see "Supporting Firefox" below
254-
.pipeTo(streamSaver.createWriteStream('conflux.zip'));
255-
```
185+
- [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream), and [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) (available in browsers since June 2022) by adding [web-streams-polyfill](https://www.npmjs.com/package/web-streams-polyfill).
186+
- [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) (available in browsers since January 2020) by setting `globalThis.JSBI` equal to [JSBI](https://github.com/GoogleChromeLabs/jsbi) before importing Conflux.
187+
- [`globalThis`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis) (available in browsers since January 2020) by adding a polyfill like this [globalthis](https://www.npmjs.com/package/globalthis) or manually setting a shim.
256188

257189
## License
258190

benchmark/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<!doctype html>
1+
<!-- prettier-ignore -->
2+
<!DOCTYPE html>
23
<html lang="en" dir="ltr">
34
<head>
45
<meta charset="utf-8" />
56
<title></title>
67
</head>
78
<body>
89
<p id="loading">Benchmarking...</p>
9-
<!-- <script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/polyfill.min.js"></script> -->
1010
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
1111
<script src="https://cdn.jsdelivr.net/npm/benchmark@2.1.4/benchmark.min.js"></script>
1212
<script src="https://cdn.jsdelivr.net/npm/jszip@3.2.2/dist/jszip.min.js"></script>

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@transcend-io/conflux",
3-
"version": "4.1.2",
3+
"version": "5.0.0",
44
"description": "Build zip files out of readable streams in the browser",
55
"main": "dist/conflux.umd.min.js",
66
"jsdelivr": "dist/conflux.umd.min.js",
@@ -98,10 +98,7 @@
9898
"tape": "^5.7.2"
9999
},
100100
"dependencies": {
101-
"@babel/runtime-corejs3": "^7.23.5",
102-
"jsbi": "^4.3.0",
103-
"pako": "^2.1.0",
104-
"web-streams-polyfill": "^3.2.1"
101+
"pako": "^2.1.0"
105102
},
106103
"packageManager": "yarn@4.5.3"
107104
}

rollup.config.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
11
import resolve from '@rollup/plugin-node-resolve';
22
import commonjs from '@rollup/plugin-commonjs';
3-
import babel from '@rollup/plugin-babel';
43
import { terser } from 'rollup-plugin-terser';
54
import pkg from './package.json';
65

7-
const babelDefaults = {
8-
// see: https://github.com/rollup/plugins/tree/master/packages/babel#babelhelpers and the note about @babel/runtime for CJS/ES
9-
babelHelpers: 'runtime',
10-
configFile: './babel.config.js',
11-
plugins: [
12-
[
13-
'@babel/plugin-transform-runtime',
14-
{
15-
regenerator: true,
16-
corejs: { version: 3, proposals: true },
17-
},
18-
],
19-
],
20-
exclude: ['node_modules/**'],
21-
};
22-
236
export default [
247
// browser-friendly UMD build
258
{
@@ -34,7 +17,6 @@ export default [
3417
plugins: [
3518
resolve(), // so Rollup can find package dependencies
3619
commonjs(), // so Rollup can convert package dependencies to an ES module
37-
babel(babelDefaults),
3820
terser(),
3921
],
4022
},
@@ -47,11 +29,10 @@ export default [
4729
// `file` and `format` for each target)
4830
{
4931
input: 'src/index.js',
50-
external: [/pako/, /jsbi/, /web-streams-polyfill/, /@babel\/runtime/],
32+
external: [/pako/],
5133
output: [
5234
// { file: pkg.main, format: 'cjs' }, // don't need a Node import yet
5335
{ file: pkg.module, format: 'es' },
5436
],
55-
plugins: [babel(babelDefaults)],
5637
},
5738
];

src/bigint.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
/* global globalThis BigInt */
22

3-
import JSBI from 'jsbi';
4-
5-
// eslint-disable-next-line import/no-mutable-exports
6-
let jsbi;
3+
if (!globalThis.BigInt && !globalThis.JSBI) {
4+
throw new Error(
5+
'BigInt is not supported in this browser.' +
6+
' Conflux is unable to create zip files without BigInt support, or a JSBI polyfill.',
7+
);
8+
}
79

810
/**
9-
* If BigInt is natively supported, change JSBI to use native expressions
10-
* @see https://github.com/GoogleChromeLabs/jsbi/blob/master/jsbi.d.ts
11-
* @see https://github.com/GoogleChromeLabs/babel-plugin-transform-jsbi-to-bigint/blob/master/src/index.js
11+
* Use JSBI syntax for BigInt operations, instead of calling BigInt directly.
12+
*
13+
* This is NOT a polyfill. It uses native BigInt by default. Using this syntax simply makes it _possible_ to polyfill BigInt.
14+
* If BigInt is not natively supported (ES2020+), library consumer MUST expose globalThis.JSBI before using Conflux.
15+
*
16+
* @see https://github.com/GoogleChromeLabs/jsbi - JSBI library for why BigInt
17+
* @see https://github.com/GoogleChromeLabs/jsbi/blob/master/jsbi.d.ts - types
1218
*/
13-
if (globalThis.BigInt) {
14-
jsbi = {};
19+
const jsbi = globalThis.JSBI || {};
1520

21+
// If BigInt is natively supported, use it instead of JSBI.
22+
if (globalThis.BigInt) {
1623
// constructor
1724
jsbi.BigInt = (a) => BigInt(a);
1825

@@ -52,8 +59,6 @@ if (globalThis.BigInt) {
5259
// static methods
5360
jsbi.asIntN = (a, b) => BigInt.asIntN(a, b);
5461
jsbi.asUintN = (a, b) => BigInt.asUintN(a, b);
55-
} else {
56-
jsbi = JSBI;
5762
}
5863

5964
export default jsbi;

0 commit comments

Comments
 (0)