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 🙏

© 2024 – Pkg Stats / Ryan Hefner

unpackmime

v0.0.1

Published

CLI for unpacking mime-multipart files,, good with LLMs

Downloads

76

Readme

unpackmime

A command line tool to unpack MIME multipart archives into files.

AI Note

I'm finding mime-multipart is a great way to talk to LLMs like Claude and ChatGPT, but the usage style is a little different so common mime tools like munpack are kind of clumsy.

In that AI spirit, this code (and this readme, except this section) were generated by Claude 3.5 in response to the detailed prompt in the prompt.md file. I had to do some debugging iterations as well, but maybe giving it a few tries would have done it as well.

Meant for use with packmime and llpipe.

Overview

unpackmime reads a MIME multipart archive and extracts each part into a separate file in the current directory. It is designed to be more lenient than standard MIME parsers, handling both CRLF and LF line endings and not requiring strictly valid MIME headers.

Installation

npm install -g unpackmime

Usage

unpackmime [options] <filename>

Options:
  --force           Overwrite existing files
  --patch           Allow overwriting files that are tracked in git and have no uncommitted changes
  --preserve        Preserve last-modified times from the archive
  --dryrun         Show what would be extracted without actually creating files
  --exclude-from=FILE  Read exclude patterns from FILE (defaults to .gitignore)

filename: Path to the MIME archive file, or "-" to read from stdin

Examples

# Extract from a file
unpackmime archive.mime

# Extract from stdin
curl https://example.com/archive | unpackmime -

# Preview what would be extracted
unpackmime --dryrun archive.mime

# Extract and preserve timestamps
unpackmime --preserve archive.mime

# Extract, allowing overwrites of clean git files
unpackmime --patch archive.mime

File Safety

By default, unpackmime is cautious about overwriting files:

  • Won't overwrite existing files without --force or --patch
  • Won't write outside the current directory
  • Won't write to paths matching .gitignore patterns
  • Won't write to .git directories

The --patch option is safer than --force as it only allows overwriting files that are:

  1. Tracked in git
  2. Have no uncommitted changes

Form Fields

HTML form fields in the MIME archive are treated as files and stored in a form-fields/ directory. For example, a form field named "user" becomes form-fields/user.

File Modes

  • Files with an X-Unix-Mode header have their mode set accordingly (e.g., X-Unix-Mode: 0755)
  • If --preserve is used, last-modified times from the archive are preserved

Errors and Warnings

  • Attempts to write outside the current directory tree will fail
  • Attempts to overwrite existing files will fail (unless --force or --patch is used)
  • Truncated archives will show a warning but extract all complete parts
  • Invalid parts are skipped with a warning

Debug Output

You can enable debug logging with the DEBUG environment variable:

# Show all debug output
DEBUG=mime:* unpackmime archive.mime

# Show only parser output
DEBUG=mime:parser unpackmime archive.mime

# Show parser and boundary detection
DEBUG=mime:parser,mime:boundary unpackmime archive.mime

MIME Format Notes

The parser is intentionally lenient:

  • Accepts both CRLF and LF line endings
  • Doesn't require Content-Type headers
  • Accepts either filename= or name= parameters
  • Handles base64 encoded content automatically
  • Processes form-data fields