# @hazae41/fleche

> Zero-copy HTTP protocol for the web

Latest version **1.4.5** (published 2024-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hazae41/fleche
pnpm add @hazae41/fleche
yarn add @hazae41/fleche
bun add @hazae41/fleche
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.5 |
| Published | 2024-09-01 |
| First published | 2023-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 348.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | hazae41 |
| Maintainers | hazae41 |
| Keywords | http, https, protocol, browser, packets, compression, messaging, encoding, decoding, connexion, webassembly, typescript, esmodules, tested, unit-tested |

## Links

- npm: https://www.npmjs.com/package/@hazae41/fleche
- Repository: https://github.com/hazae41/fleche
- Issues: https://github.com/hazae41/fleche/issues
- npm.io page: https://npm.io/package/@hazae41/fleche

## Dependencies (8)

- [@hazae41/bytes](https://npm.io/package/@hazae41/bytes.md) ^1.2.11
- [@hazae41/base64](https://npm.io/package/@hazae41/base64.md) ^1.0.15
- [@hazae41/binary](https://npm.io/package/@hazae41/binary.md) ^1.3.5
- [@hazae41/cursor](https://npm.io/package/@hazae41/cursor.md) ^1.2.4
- [@hazae41/future](https://npm.io/package/@hazae41/future.md) ^1.0.3
- [@hazae41/cascade](https://npm.io/package/@hazae41/cascade.md) ^2.2.2
- [@hazae41/signals](https://npm.io/package/@hazae41/signals.md) ^1.0.2
- [@hazae41/disposer](https://npm.io/package/@hazae41/disposer.md) ^2.0.20

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.4.5 (latest) — 2024-09-01
- 1.4.4 — 2024-03-27
- 1.4.3 — 2024-03-14
- 1.4.2 — 2024-03-14
- 1.4.1 — 2024-03-14
- 1.4.0 — 2024-03-14
- 1.3.0 — 2024-03-11
- 1.2.15 — 2024-02-08
- 1.2.14 — 2024-02-08
- 1.2.13 — 2024-02-08
- 1.2.12 — 2023-12-23
- 1.2.11 — 2023-12-23
- 1.2.10 — 2023-12-23
- 1.2.9 — 2023-11-30
- 1.2.8 — 2023-11-27
- … 124 more at https://npm.io/package/@hazae41/fleche/versions

## README

<div align="center">
<img src="https://user-images.githubusercontent.com/4405263/219943458-f5fa0f94-8dfd-4f8e-9fb5-df780a600dd4.png" />
</div>

```bash
npm i @hazae41/fleche
```

[**Node Package 📦**](https://www.npmjs.com/package/@hazae41/fleche)

## Features

### Goals
- 100% TypeScript and ESM
- Zero-copy reading and writing
- Transport agnostic (TCP, TLS, Tor)
- Supports backpressure

### HTTP
- HTTP 1.1
- Native Gzip and Deflate compression
- Compatible with code using `fetch`
- Reusable underlying connection

### WebSocket
- Relies on the above HTTP
- Powered by WebAssembly
- Same API than native
- Only 0.3ms slower than native

### [Upcoming features](https://github.com/sponsors/hazae41)
- More HTTP 1.1 features
- HTTP 2, HTTP 3 (QUIC)

## Usage

```tsx
import { Opaque, Writable } from "@hazae41/binary"
import { fetch } from "@hazae41/fleche"

function example(stream: ReadableWritablePair<Opaque, Writable>) {
  /**
   * Fetch using the underlying TCP or TLS stream
   */
  const res = await fetch("https://example.com", { stream })

  if (!res.ok)
    throw new Error(await res.text())

  return await res.json()
}
```

```tsx
import { Opaque, Writable } from "@hazae41/binary"
import { WebSocket } from "@hazae41/fleche"

function example(stream: ReadableWritablePair<Opaque, Writable>) {
  const socket = new WebSocket("wss://example.com")

  /**
   * Pipe TCP or TLS input to WebSocket input
   */
  stream.readable
    .pipeTo(socket.inner.writable, { preventCancel: true })
    .catch(() => {})

  /**
   * Pipe WebSocket output to TCP or TLS output
   */
  socket.inner.readable
    .pipeTo(stream.writable, { preventClose: true, preventAbort: true })
    .catch(() => {})

  await new Promise((ok, err) => {
    socket.addEventListener("open", ok)
    socket.addEventListener("error", err)
  })

  socket.addEventListener("message", e => console.log(e.data))
  socket.send("Hello world")
}

---
_Source: https://npm.io/package/@hazae41/fleche · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
