1.1.0 • Published 4 years ago

@anandsuresh/smart-stream v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

smart-stream

node (scoped) npm (scoped) npm Travis license GitHub followers Twitter Follow

A smart stream provides the abstraction of a stream of bytes. It has the following properties:

  • contentType: representing the MIME type of that the stream of bytes represent
  • contentEncoding: representing the type of encoding (gzip, deflate, identity)
  • contentLength: the length of the stream, in bytes. Not always available.

Usage

const {fromFile, fromHttpRequest} = require('smart_stream')

async function handleRequest(req, res) {
  try {
    const inStream = fromHttpRequest(req)
    if (!inStream.isDeserializable) {
      res.statusCode = 400
      return res.end()
    }

    const obj = await stream.toObject()

    // Do something with the object
    // Then respond with a file

    fromFile('/path/to/file.jpg', {contentType: 'image/jpeg'}).pipe(res)
  } catch (err) {
    res.statusCode = 500
    res.end(err.stack)
  }
}
1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago