close
Skip to main content
This release is versions behind 0.28.8 — the latest version of @xpr/jsocket.

@xpr/jsocket@0.25.0
Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score94%
Downloads1/wk
Publisheda year ago (0.25.0)

Read and write stream. Supports ReadableStream, WritableStream, and Node.js streams.

Examples

read from any readable stream

import { read } from "@xpr/jsocket/read";

const stream = getReadableStream();
const data = await read(stream);

write to any writable stream

import { write } from "@xpr/jsocket/write";

const stream = getWritableStream();
await write(stream, data);

Creating a Unix socket server and client

example server:

import createServer from "@xpr/jsocket/server";

await createServer("/tmp/my-socket", async (buf: string) => {
   return buf.toUpperCase();
});

example client:

import request from "@xpr/jsocket/request";

const response = await request("/tmp/my-socket", "Hello, world!");
console.log(response); // HELLO, WORLD!

Functions

f
client<B extends ValueType, R extends ValueType>(
path: string,
body: B
): Promise<R>

Create a Unix socket client and make a request.

f
read(stream: ReadableStream<Uint8Array>): Promise<Uint8Array>

Read data from a readable stream. Reads until the stream is closed or an EOF byte is encountered.

f
server(
path: string,
handler: ConnectionHandler
): UnixTransportServer<Deno.Listener>

Create and start listening to Unix socket server.

f
write(
stream: WritableStream<Uint8Array>,
data: Uint8Array
): Promise<void>

Write data to a writable stream in chunks of 1024 bytes.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@xpr/jsocket

Import symbol

import * as mod from "@xpr/jsocket";
or

Import directly with a jsr specifier

import * as mod from "jsr:@xpr/jsocket";