npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zmodem2

v1.2.1

Published

ZMODEM file transfer protocol library for JavaScript/TypeScript

Readme

zmodem2-js

Notice:

This project is a JavaScript/TypeScript port of the zmodem2 Rust crate. Part of the code was generated by KiloCode's GLM5 model (z.ai).

All credit goes to the original author, Jarkko Sakkinen.

中文文档 | English

A modern ZMODEM file transfer protocol library for JavaScript/TypeScript. This library provides stream-like state machines for sending and receiving files with the ZMODEM protocol, suitable for both Node.js and browser environments.

Features

  • Cross-platform: Works in Node.js and browser environments
  • TypeScript native: Full TypeScript support with declaration files
  • Multiple module formats: ESM, CommonJS, and bundled versions
  • Tree-shakeable: ESM output supports tree shaking for optimal bundle sizes
  • Zero runtime dependencies: Lightweight and self-contained
  • Streaming API: Efficient handling of large files through streaming operations

Installation

npm install zmodem2

Module Formats

This package provides multiple output formats to suit different use cases:

| Format | Path | Description | |--------|------|-------------| | ESM | dist/esm/ | ES modules, tree-shakeable, no bundled dependencies | | CommonJS | dist/cjs/ | CommonJS modules, no bundled dependencies | | CommonJS Full | dist/cjs-full/ | CommonJS bundle with all code in a single file | | Browser | dist/browser/ | IIFE format for direct browser usage |

Usage

ES Modules (ESM) - Recommended for bundlers

For use with modern bundlers (webpack, rollup, vite, etc.) that support tree shaking:

import { Sender, Receiver, ZmodemError } from 'zmodem2'

// Create a sender for file transfer
const sender = new Sender()

// Create a receiver for file reception
const receiver = new Receiver()

CommonJS - Node.js

For Node.js environments using require():

const { Sender, Receiver, ZmodemError } = require('zmodem2')

// Create a sender for file transfer
const sender = new Sender()

// Create a receiver for file reception
const receiver = new Receiver()

CommonJS Full Bundle - Node.js (All-in-one)

For environments where you want all code bundled in a single file:

const zmodem2 = require('zmodem2/cjs-full')

const { Sender, Receiver } = zmodem2

// Use Sender and Receiver
const sender = new Sender()

Browser (IIFE/UMD)

For direct browser usage without a bundler:

<script src="node_modules/zmodem2/dist/browser/zmodem2.min.js"></script>
<script>
  // Global variable: Zmodem2
  const sender = new Zmodem2.Sender()
  const receiver = new Zmodem2.Receiver()
</script>

Or via CDN:

<script src="https://unpkg.com/zmodem2/dist/browser/zmodem2.min.js"></script>

API Overview

Core Classes

Sender

Handles sending files via ZMODEM protocol.

const sender = new Sender()

// Get bytes to send over the wire
const outgoingBytes = sender.drainOutgoing()

// After writing bytes, advance the state
sender.advanceOutgoing()

// Feed incoming bytes from the remote
sender.feedIncoming(bytes)

// Send a file
const fileRequest = sender.pollFile()
if (fileRequest) {
  sender.feedFile(fileData)
}

// Check for events
const event = sender.pollEvent()

Receiver

Handles receiving files via ZMODEM protocol.

const receiver = new Receiver()

// Get bytes to send over the wire
const outgoingBytes = receiver.drainOutgoing()

// After writing bytes, advance the state
receiver.advanceOutgoing()

// Feed incoming bytes from the remote
receiver.feedIncoming(bytes)

// Receive file data
const fileBytes = receiver.drainFile()
if (fileBytes) {
  // Write to storage
  receiver.advanceFile()
}

// Check for events
const event = receiver.pollEvent()

Events

Both Sender and Receiver emit events through pollEvent():

enum SenderEvent {
  Ready = 'ready',
  FileRequest = 'fileRequest',
  Sent = 'sent',
  Error = 'error',
  Complete = 'complete'
}

enum ReceiverEvent {
  Ready = 'ready',
  FileStart = 'fileStart',
  FileData = 'fileData',
  FileEnd = 'fileEnd',
  Error = 'error',
  Complete = 'complete'
}

Error Handling

import { ZmodemError, NotConnectedError, ReadError, WriteError } from 'zmodem2'

try {
  // ZMODEM operations
} catch (error) {
  if (error instanceof ZmodemError) {
    console.error('ZMODEM error:', error.message)
  }
}

Constants and Utilities

import {
  // Constants
  ZPAD, ZDLE, XON,
  SUBPACKET_MAX_SIZE, SUBPACKET_PER_ACK,
  
  // CRC utilities
  crc16Xmodem, crc32IsoHdlc,
  Crc16, Crc32,
  
  // ZDLE encoding
  ZDLE_TABLE, UNZDLE_TABLE,
  escapeByte, unescapeByte,
  
  // Header types
  Encoding, Frame,
  Zrinit, Header,
  decodeHeader, createZrinit
} from 'zmodem2'

TypeScript Support

This package includes TypeScript declaration files. No additional @types/ package is needed.

import {
  Sender,
  Receiver,
  SenderEvent,
  ReceiverEvent,
  FileRequest,
  ZmodemError
} from 'zmodem2'

const sender: Sender = new Sender()
const event: SenderEvent | null = sender.pollEvent()

Building from Source

# Clone the repository
git clone https://github.com/zxdong262/zmodem2-js.git
cd zmodem2-js

# Install dependencies
npm install

# Build all formats
npm run build

# Build specific format
npm run build:esm    # ESM only
npm run build:cjs    # CommonJS only
npm run build:types  # Declaration files only

Build Output Structure

dist/
  esm/           # ES modules (tree-shakeable)
    index.js
    index.d.ts
    ...
  cjs/           # CommonJS modules
    index.cjs
    index.d.ts
    ...
  cjs-full/      # Bundled CommonJS
    index.cjs
    index.d.ts
  browser/       # Browser bundle
    zmodem2.js
    zmodem2.min.js
    index.d.ts

Testing

# Run unit tests
npm test

# Run integration tests
npm run test:upload
npm run test:download

# Watch mode
npm run test:watch

License

MIT License - see LICENSE for details.

Related Projects

  • zmodem2-wasm - WebAssembly implementation for high-performance CRC calculations
  • electerm - Terminal app with ZMODEM support which uses this library for ZMODEM file transfers