Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
489 changes: 277 additions & 212 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

74 changes: 74 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Deploy site to GitHub Pages

on:
push:
branches: [main, feat/new_arch]
paths:
- '.github/workflows/pages.yml'
- 'docs/**'
- 'site/**'
- 'web/**'
- 'scripts/build-site.mjs'
- 'scripts/test-site.mjs'
- 'scripts/test-site-browser.mjs'
- 'package.json'
- 'yarn.lock'
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: pages
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: yarn

- name: Enable Corepack
run: corepack enable

- name: Install dependencies
run: yarn install --immutable

- name: Build documentation site
run: yarn site:build

- name: Validate site structure
run: yarn site:test

- name: Test Playground in Chrome
env:
CHROME_PATH: /usr/bin/google-chrome
run: yarn site:test:browser

- name: Configure GitHub Pages
uses: actions/configure-pages@v5

- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@v4
with:
path: site-dist

deploy:
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ android/keystores/debug.keystore

# generated by bob
lib/
site-dist/
27 changes: 27 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,26 @@ Remember to add tests for your change if possible. Run the unit tests by:
yarn test
```

Web implementation changes should also pass:

```sh
yarn test:web
yarn test:web:browser
yarn test:web:metro
```

Documentation and site changes should pass:

```sh
yarn site:build
yarn site:test
yarn site:test:browser
```

Public English guides live in `docs/`, with their Chinese mirrors in
`docs/zh-CN/`. Keep both languages aligned when a change affects API behavior,
platform support, errors, or operational guidance.

### Commit message convention

We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages:
Expand Down Expand Up @@ -108,6 +128,13 @@ The `package.json` file contains various scripts for common tasks:
- `yarn example start`: start the Metro server for the example app.
- `yarn example android`: run the example app on Android.
- `yarn example ios`: run the example app on iOS.
- `yarn build:web`: regenerate the checked-in WebAssembly bundle with Emscripten.
- `yarn test:web`: verify the WebAssembly patch format and round trip.
- `yarn test:web:browser`: exercise the public Web Worker API in Chrome.
- `yarn test:web:metro`: verify Metro resolves the React Native Web entry.
- `yarn site:build`: render public Markdown and static site assets into `site-dist/`.
- `yarn site:test`: validate site structure and local links.
- `yarn site:test:browser`: verify the live Playground, docs, and mobile viewport.

### Sending a pull request

Expand Down
130 changes: 115 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,137 @@
# react-native-bs-diff-patch

rn bs diff patch file
Create a compact binary patch from two versions of a file, then reconstruct the
new version from the old file and that patch. Android, iOS, and React Native Web
all use the compatible `ENDSLEY/BSDIFF43` wire format.

[Documentation](https://bs-dff-patch.corerobin.com/docs/) ·
[Playground](https://bs-dff-patch.corerobin.com/#playground) ·
[中文说明](./README.zh-CN.md) · [npm](https://www.npmjs.com/package/react-native-bs-diff-patch)

## Why use it?

- **One patch format:** generate on one supported runtime and apply on another.
- **Both React Native architectures:** legacy bridge and TurboModule/New Architecture.
- **Responsive by default:** native work uses dedicated serial queues; Web work
runs in an isolated module Worker.
- **No Web service required:** the browser implementation is the same bundled C
core compiled to WebAssembly.

| Runtime | Input model | Create a patch | Apply a patch |
| ------------ | ------------------ | -------------- | ------------- |
| Android, iOS | Absolute paths | `diff` | `patch` |
| Web | In-memory binaries | `diffBytes` | `patchBytes` |

## Installation

```sh
npm install react-native-bs-diff-patch
```

## Usage
After adding the package, install iOS pods and rebuild the native app:

```sh
npx pod-install
```

React Native autolinking handles native registration. A Metro reload alone is
not enough after adding a native dependency.

## Native quick start

```js
The native API works with absolute file paths. Use the filesystem library
already present in your app to select a writable cache directory.

```ts
import { diff, patch } from 'react-native-bs-diff-patch';

// ...
type NativeRoundTripOptions = {
oldFilePath: string;
newFilePath: string;
cacheDirectory: string;
};

export async function nativeRoundTrip({
oldFilePath,
newFilePath,
cacheDirectory,
}: NativeRoundTripOptions) {
const runId = Date.now();
const patchPath = `${cacheDirectory}/update-${runId}.patch`;
const restoredPath = `${cacheDirectory}/restored-${runId}.bin`;

await diff(oldFilePath, newFilePath, patchPath);
await patch(oldFilePath, restoredPath, patchPath);

return { patchPath, restoredPath };
}
```

Output paths must not exist, all paths in one call must be different, and the
required input files must already exist. Both functions resolve to `0` on
success.

## React Native Web quick start

/**
* generate patch file from old file and new file
*/
await diff(oldFile, newFile, patchFile);
// generate new file from old file and patch file
await patch(oldFile, newFile, patchFile);
```ts
import { diffBytes, patchBytes } from 'react-native-bs-diff-patch';

export async function webRoundTrip(oldFile: File, newFile: File) {
const oldData = await oldFile.arrayBuffer();
const newData = await newFile.arrayBuffer();
const patchData = await diffBytes(oldData, newData);
const restoredData = await patchBytes(oldData, patchData);

return { patchData, restoredData };
}
```

`diffBytes` and `patchBytes` accept `ArrayBuffer`, any `ArrayBufferView`
(including typed arrays and `DataView`), or `Blob`. They resolve to a new
`Uint8Array` and leave the caller's buffers usable.

## Platform API matrix

| API | Android | iOS | Web |
| --------------------------------------- | ------- | --- | --- |
| `diff(oldPath, newPath, patchPath)` | Yes | Yes | No |
| `patch(oldPath, outputPath, patchPath)` | Yes | Yes | No |
| `diffBytes(oldData, newData)` | No | No | Yes |
| `patchBytes(oldData, patchData)` | No | No | Yes |
| Legacy architecture | Yes | Yes | N/A |
| New Architecture / TurboModule | Yes | Yes | N/A |

Calling an API family that is unavailable on the current platform rejects with
`EUNSUPPORTED` instead of silently choosing different behavior.

## Production checklist

- Verify the restored output before replacing application data.
- Authenticate patches from remote or otherwise untrusted sources.
- Use unique native output paths and clean temporary files after success or failure.
- Set product-specific input-size and time limits; binary diffing can use
several times the input size in peak memory.
- Generate and apply patches with this library. Generic `BSDIFF40` patches are
not interchangeable with `ENDSLEY/BSDIFF43` patches.

See [Production recipes](./docs/recipes.md) for error handling, downloads,
cross-runtime patch exchange, and integrity checks.

## Documentation

- [Getting started](./docs/getting-started.md)
- [API reference](./docs/api-reference.md)
- [Production recipes](./docs/recipes.md)
- [Platform support](./docs/platform-support.md)
- [Architecture and patch format](./docs/architecture.md)
- [Troubleshooting](./docs/troubleshooting.md)
- [Development and verification](./docs/development.md)

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
See [CONTRIBUTING.md](./CONTRIBUTING.md) for the local workflow and quality
gates.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
Loading
Loading