Skip to content

Path.open() method

pathlib-ts > Path > open

Open the file with the given mode and return a Node.js stream-like handle.

Signature:

open(mode?: string): Promise<fs.ReadStream>;

Parameter

Type

Description

mode

string

(Optional) CPython-style mode string (for example "r", "wb").

Returns:

Promise<fs.ReadStream>

Promise resolving to a fs.ReadStream.

Delegates to magicOpen utility to match CPython defaults while still returning a Node.js compatible stream proxy.

Streaming a log file asynchronously

import { Path } from "pathlib-ts";
const log = new Path("./logs/server.log");
const stream = await log.open("r");
stream.on("data", (chunk) => process.stdout.write(chunk));