escpos-ts API - v1.0.0
    Preparing search index...

    Interface IPrinterConnection

    Hardware-agnostic contract for a printer transport layer.

    All concrete printer classes (Network, Usb) implement this interface so that higher-level code can treat any transport uniformly. Pass an IPrinterConnection to a dependency-injection boundary or a test double to decouple printing logic from hardware.

    import type { IPrinterConnection } from 'escpos-ts';

    function printReceipt(conn: IPrinterConnection, lines: string[]): Promise<void> {
    await conn.open();
    for (const line of lines) await conn.write(Buffer.from(line + '\n'));
    await conn.close();
    }

    1.0.0

    interface IPrinterConnection {
        close(): Promise<void>;
        open(): Promise<void>;
        read(length?: number): Promise<Buffer<ArrayBufferLike>>;
        write(data: Buffer): Promise<void>;
    }
    Index

    Methods

    • Read bytes from the printer.

      Used to retrieve status bytes or responses to ESC/POS real-time status commands (DLE EOT).

      Parameters

      • Optionallength: number

        Maximum number of bytes to read. If omitted, returns the first full data chunk received.

      Returns Promise<Buffer<ArrayBufferLike>>

      Promise resolving with a Buffer containing received data.

      DeviceNotFoundError if the connection is not open.

    • Write raw bytes to the printer.

      The returned promise resolves when the write has been accepted by the underlying transport layer — not necessarily when the printer has physically processed the data.

      Parameters

      • data: Buffer

        Buffer containing the raw bytes to transmit.

      Returns Promise<void>

      Promise that resolves on successful acceptance by the transport.

      DeviceNotFoundError if the connection is not open.