MCPcopy Index your code
hub / github.com/chjj/parted

github.com/chjj/parted @v0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.1 ↗ · + Follow
26 symbols 60 edges 9 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

parted

Parted is a streaming multipart, json, and urlencoded parser for node.js, written from scratch. It comes bundled with an express middleware which will use the necessary parser depending on the request mime type. Each parser is also lazily loaded, so there is no unnecessary memory usage if you only need one of them.

The middleware will leave you with a req.body object, similar to the default body parser included in express. If a file was included with a multipart request, a temporary path to the uploaded file is provided in req.body. The multipart parser will also create a req.files object specifically for files if you prefer.

Every parser handles nested fields in the same way node-querystring does.

Note; Although the JSON and qs/encoded parsers are streaming, they're disabled by default and buffering parsers are used instead. Use the stream option to enable them.

Install

$ npm install parted

As a middleware

var parted = require('parted');

app.use(parted({
  // custom file path
  path: __dirname + '/uploads',
  // memory usage limit per request
  limit: 30 * 1024,
  // disk usage limit per request
  diskLimit: 30 * 1024 * 1024,
  // enable streaming for json/qs
  stream: true
}));

When multiple is disabled only a single part will be present for a given name, for example:

{ image: '/tmp/bigred.1319577761529.png' }

However when multiple is enabled, this may be an array:

{ images:
   [ '/tmp/bigred-pau.1319577761529.png',
     '/tmp/bigred-ico.1319577761528.png',
     '/tmp/bigred-rec.1319577761529.png',
     '/tmp/bigred-sto.1319577761529.png',
     '/tmp/bigred.1319577761529.png' ] }

Usage

The multipart parser alone

var multipart = require('parted').multipart;

var options = {
  limit: 30 * 1024,
  diskLimit: 30 * 1024 * 1024
};

var parser = new multipart(type, options)
  , parts = {};

parser.on('error', function(err) {
  req.destroy();
  next(err);
});

parser.on('part', function(field, part) {
  // temporary path or string
  parts[field] = part;
});

parser.on('data', function() {
  console.log('%d bytes written.', this.written);
});

parser.on('end', function() {
  console.log(parts);
});

req.pipe(parser);

Running tests

$ node test

Core symbols most depended-on inside this repo

next
called by 20
lib/multipart.js
load
called by 8
lib/index.js
unescape
called by 7
lib/qs.js
set
called by 4
lib/qs.js
handle
called by 3
lib/index.js
output
called by 3
lib/json.js
grab
called by 3
lib/multipart.js
multiple
called by 3
test/index.js

Shape

Function 26

Languages

TypeScript100%

Modules by API surface

test/index.js10 symbols
lib/qs.js5 symbols
lib/multipart.js4 symbols
lib/json.js3 symbols
lib/index.js2 symbols
test/real/index.js1 symbols
lib/encoded.js1 symbols

For agents

$ claude mcp add parted \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact