Path.open() method
pathlib-ts > Path > open
Path.open() method
Section titled “Path.open() method”Open the file with the given mode and return a Node.js stream-like handle.
Signature:
open(mode?: string): Promise<fs.ReadStream>;Parameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
mode |
string |
(Optional) CPython-style mode string (for example |
Returns:
Promise<fs.ReadStream>
Promise resolving to a fs.ReadStream.
Remarks
Section titled “Remarks”Delegates to magicOpen utility to match CPython defaults while still returning a Node.js compatible stream proxy.
Example
Section titled “Example”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));