@unikvs/passthrough
Middleware that passes data through without conversion.
Overview
@unikvs/passthrough passes data through without any conversion.Middleware
It fits empty pipeline slots or serves as a base for custom middleware. Alone, it never changes stored content.
nameisPassThrough.isOpenis alwaystrue.open()is unnecessary.
Install with:
npm install @unikvs/passthrough @logtape/logtapepnpm add @unikvs/passthrough @logtape/logtapeyarn add @unikvs/passthrough @logtape/logtapebun add @unikvs/passthrough @logtape/logtapenub add @unikvs/passthrough @logtape/logtapeaube add @unikvs/passthrough @logtape/logtapeUsage
PassThrough implements IMiddleware. Pass it to UniKvs with use().
import { PassThrough } from "@unikvs/passthrough";
The following stores a value through passthrough and reads it back unchanged:
import { Memory } from "@unikvs/memory";
import { PassThrough } from "@unikvs/passthrough";
import * as unikvs from "unikvs";
const kvs = new unikvs.Builder<{ foo: unikvs.Value<Uint8Array> }>()
.use(new PassThrough())
.persist(new Memory())
.build();
await kvs.open();
await kvs.set("foo", new Uint8Array([0, 1, 2]));
const bytes = await kvs.get("foo");
console.log(bytes); // Uint8Array(3) [0, 1, 2]
await kvs.close();
Data types
| Method | Input | Output |
|---|---|---|
encode |
TData |
TData |
decode |
TData |
TData |
encodeStream |
TChunk |
TChunk |
decodeStream |
TChunk |
TChunk |
encodeoutputs the input data unchanged.decodeoutputs the input data unchanged.encodeStreamoutputs the input stream unchanged.decodeStreamoutputs the input stream unchanged.
Errors
This package has no package-specific errors.