# @har-tools/stream

> Create a stream of HAR entries from the Fetch API Request/Response instances

Latest version **0.1.2** (published 2023-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @har-tools/stream
pnpm add @har-tools/stream
yarn add @har-tools/stream
bun add @har-tools/stream
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2023-10-12 |
| First published | 2023-10-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 47.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Artem Zakharchenko |
| Maintainers | kettanaito |
| Keywords | har, archive, transform, fetch, entry, request, response |

## Links

- npm: https://www.npmjs.com/package/@har-tools/stream
- npm.io page: https://npm.io/package/@har-tools/stream

## Dependencies (4)

- [@types/har-format](https://npm.io/package/@types/har-format.md) ^1.2.13
- [set-cookie-parser](https://npm.io/package/set-cookie-parser.md) ^2.6.0
- [@har-tools/http-message](https://npm.io/package/@har-tools/http-message.md) ^0.1.2
- [@open-draft/deferred-promise](https://npm.io/package/@open-draft/deferred-promise.md) ^2.2.0

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2023-10-12
- 0.1.1 — 2023-10-12
- 0.1.0 — 2023-10-11

## README

# `@har-tools/stream`

Create a stream of HAR entries from the Fetch API Request/Response instances.

## Installation

```sh
npm install @har-tools/stream
```

## Usage

```js
import { HarStream, NetworkEntry } from '@har-tools/stream'

// Create an HAR stream.
const stream = new HarStream()

// Create a new network entry.
const entry = new NetworkEntry(new Request('https://example.com'))

// Write the network entry early.
// As soon as you ".end()" the entry with a Response,
// the stream will emit the complete HAR entry.
stream.write(entry)

// Call the ".end()" method once you receive the response.
entry.end(new Response('Hello world'))
```

Listening to HAR entries:

```js
stream.on('data', (entry) => {
  // Observe generated HAR entries as they come in.
  console.log(entry.request, entry.response)
})
```

Stop the stream:

```js
stream.destroy()
```

## Timings

You can control the network entry timings using the `entry.timings` API. It provides you with the methods you have to call _sequentially_ to indicate various staged of the request.

**The order of the timing metrics:**

1. `socketOpened`, socket opened but not connected yet.
1. `dnsLookupEnd`, socket has resolved the DNS name.
1. `connected`, socket has connected.
1. `connectedSecure` (_Optional_)
1. `requestEnd`, request is finished (request headers and body sent).
1. `responseStart`, first byte of the response received.
1. `responseEnd`, last byte of the response received.

Entry timings are _dependent_, so if the previous timing is missing, the next one will not be calculated. For example, if `entry.timings.dnsLookupEnd()` was never called, the network entry will have both `dns` and `connected` timings as `-1`.

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