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

ee-mime-decoder

v0.1.13

Published

streaming mime message decoder, supports streaming of attachments & file uploads

Downloads

4

Readme

ee-mime-decoder

decode mime messages. the decoder implements the interface of a writable stream ( v2 ) and a object readable stream ( v2 ). if the decoder encounters binary data like a file upload it will return a separate readable stream for every binary part which is found in the mime message. each of this streams must be consumed, else the decoding of the message will never finish.

If you need to decode mime messages from a http form request you should use the «ee-formdata-reader» module which is much simpler then this module.

installation

npm install ee-mime-decoder

build status

Build Status

usage

usage

var   MimeDecoder 		= require('ee-mime-decoder')
	, StreamCollector 	= require('ee-stream-collector');


webserver.on('request', function(req, res){

	if (req.method === 'POST'){
		// if the message is already partially parsed you nede to set the content type header 
		// in the constructor, this is the case when parsing multipart messages sent by
		// the browser.
		// if you're parsing emails the headers are already embedded in the emails, so you 
		// don't have to provide them via the constructor.
		var decoder = new MimeDecoder(request.headers['Content-Type']); // multipart/mixed; boundary="----------------------------722570873451616639732247"

		// send data from request directly to the decoder
		req.pipe(decoder);


		// handle incoming decoded mime message parts
		decoder.on('data', function(obj){
			if (obj.isStream()) {
				// mime objet implementing the readable stream interface
				// we got a binary mime part ( e.g. attachment, file upload )

				if (iWantToCacheTheFileInMemory){
					// collect data an store on the mime object

					var collector = new StreamCollector();
					collector.on('end', function(){
						// store the data on the mime object
						obj.data = collector.data;
					} );

					// pipe data into collector
					obj.pipe(collector);
				}
				else if (iWantToStoreTheFilesInTheFileSystem){
					// store the file in the fs
					ob.pipe(fs.createWriteStream('/path/to/the/new/file'));

					// we need to know where the data was stored
					obj.path = '/path/to/the/new/file';
				}
				else {
					// do whatever you want
				}
			}
			else {
				// mime object, we dont need to store the data because its stored on the mimeMessage object of the collector
				console.dir(obj);
				// {
				//    parts: (2):[
				//        0: {
				//            length: 19
				//            , data: "[email protected]"
				//        }
				//        , 1: {
				//            length: 14
				//            , data: "securePassword"
				//        }
				//    ]
				//    , length: 2
				//}
			}
		} );


		// all data was received, we can now work with it
		decoder.on('end', function(){
			var mimeMessage = decoder.getMessage();

			mimeMessage.parts.forEach(function(part){
				console.log(part.length, part.getHeader('content-type'));
				if (part.hasChildren()) console.log('the part has %s children', part.parts.length);
			} );
		} );
	}
} );