{"_id":"file-type-stream","_rev":"4207970","name":"file-type-stream","description":"Wrapper over file-type that makes using it with streams easier.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"time":{"modified":"2026-03-04T17:04:20.000Z","created":"2016-09-30T00:14:54.125Z","1.0.0":"2016-09-30T00:14:54.125Z"},"users":{},"author":{"name":"Oli Lalonde","email":"olalonde@gmail.com","url":"https://syskall.com/"},"repository":{"type":"git","url":"git+https://github.com/blockai/file-type-stream.git"},"versions":{"1.0.0":{"name":"file-type-stream","version":"1.0.0","description":"Wrapper over file-type that makes using it with streams easier.","main":"./lib/index.js","directories":{"test":"test"},"scripts":{"test":"npm run test:fast","build":"npm run clean && babel ./src --out-dir ./lib --copy-files","clean":"rimraf ./lib","lint":"eslint src/ test/","pretest":"npm run lint","test:fast":"babel-tape-runner test/*.test.js","test:watch":"nodemon --exec npm -- run --silent test:fast || true","semantic-release":"git push && npm test && semantic-release pre && npm run build && npm publish && semantic-release post"},"repository":{"type":"git","url":"git+https://github.com/blockai/file-type-stream.git"},"keywords":[],"author":{"name":"Oli Lalonde","email":"olalonde@gmail.com","url":"https://syskall.com/"},"license":"MIT","bugs":{"url":"https://github.com/blockai/file-type-stream/issues"},"homepage":"https://github.com/blockai/file-type-stream#readme","engines":{"node":">=6"},"devDependencies":{"babel-cli":"^6.16.0","babel-preset-blockai":"^1.0.0","babel-tape-runner":"^2.0.1","blue-tape":"^1.0.0","common-streams":"^1.4.0","concat-stream":"^1.5.2","cz-conventional-changelog":"^1.2.0","eslint-config-blockai":"^1.0.1","kitchenfile":"^1.0.2","nodemon":"^1.10.2","rimraf":"^2.5.4","semantic-release":"^4.3.5"},"release":{"debug":false,"verifyConditions":{"path":"./node_modules/semantic-release/dist/lib/plugin-noop.js"}},"config":{"commitizen":{"path":"cz-conventional-changelog"}},"dependencies":{"file-type":"^3.8.0"},"gitHead":"38697d996c8e333333ac335cd6ca4efa3077a0cb","_id":"file-type-stream@1.0.0","_shasum":"dd0a1edd1f5fe973623ed6fe16be19c8931b44c3","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.6.0","_npmUser":{"name":"olalonde","email":"olalonde@gmail.com"},"dist":{"shasum":"dd0a1edd1f5fe973623ed6fe16be19c8931b44c3","size":3156,"noattachment":false,"key":"/file-type-stream/-/file-type-stream-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/file-type-stream/download/file-type-stream-1.0.0.tgz"},"maintainers":[{"name":"olalonde","email":"olalonde@gmail.com"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/file-type-stream-1.0.0.tgz_1475194491791_0.6284204397816211"},"_cnpmcore_publish_time":"2021-12-19T19:33:50.725Z","publish_time":1475194494125,"_cnpm_publish_time":1475194494125}},"readme":"# file-type-stream\n\n[![Build Status](https://travis-ci.org/blockai/file-type-stream.svg?branch=master)](https://travis-ci.org/blockai/file-type-stream)\n\nWrapper over [file-type](https://github.com/sindresorhus/file-type) that\nmakes using it with streams easier.\n\n## Install\n\n```bash\nnpm install --save file-type-stream\n```\n\nRequires Node v6+\n\n## Usage\n\n```\nfileTypeStream(callback)\n```\n\nSee [./test](./test) directory for usage examples.\n\n```javascript\nimport fileTypeStream from 'file-type-stream'\nimport { PassThrough } from 'stream'\n\n// ...\n// s3Client = ....\n// ...\n\nconst through = new PassThrough()\nreadStream.pipe(fileTypeStream((type) => {\n  // since transform streams buffer up to 16kb which\n  // is enough to detect the file type, we get\n  // the file type even through through hasn't been piped\n  // anywhere yet.\n\n  console.log('ext', type.ext)\n  console.log('mime', type.mime)\n\n  // E.g.:\n  // We can use that info to open a write stream on aws s3\n  // with the correct content type\n  client.upload({\n    ContentType: type.mime,\n    Bucket: 'some-bucket',\n    Key: 'some-key',\n    Body: through,\n  }, null, (err) => {\n    // Upload completed!\n  })\n})).pipe(through)\n```\n\nThe code above can be written a bit more intuitively with async/await:\n\n```javascript\n\nimport fileTypeStream from 'file-type-stream'\nimport { PassThrough } from 'stream'\n\n// ...\n// s3Client = ....\n// ...\n\nconst upload = async (rs) => {\n  const Body = new PassThrough()\n\n  const { mime } = await new Promise(resolve => {\n    rs.pipe(fileTypeStream(resolve)).pipe(Body)\n  })\n  const response = client.upload({\n    Body,\n    ContentType: mime,\n    Bucket: 'some-bucket',\n    Key: 'some-key',\n  }).toPromise()\n\n  console.log(response)\n}\n```","_attachments":{},"homepage":"https://github.com/blockai/file-type-stream#readme","bugs":{"url":"https://github.com/blockai/file-type-stream/issues"},"license":"MIT"}