{"id":20766989,"url":"https://github.com/binded/file-type-stream","last_synced_at":"2025-05-11T08:34:08.823Z","repository":{"id":57235650,"uuid":"69614716","full_name":"binded/file-type-stream","owner":"binded","description":"Wrapper over file-type that makes using it with streams easier","archived":true,"fork":false,"pushed_at":"2016-09-30T00:14:55.000Z","size":24,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-20T14:17:51.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binded.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-29T23:02:54.000Z","updated_at":"2025-03-11T07:58:53.000Z","dependencies_parsed_at":"2022-08-31T14:11:42.839Z","dependency_job_id":null,"html_url":"https://github.com/binded/file-type-stream","commit_stats":null,"previous_names":["blockai/file-type-stream"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Ffile-type-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Ffile-type-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Ffile-type-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Ffile-type-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/file-type-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253540462,"owners_count":21924522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T11:27:08.061Z","updated_at":"2025-05-11T08:34:04.127Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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) =\u003e {\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) =\u003e {\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) =\u003e {\n  const Body = new PassThrough()\n\n  const { mime } = await new Promise(resolve =\u003e {\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```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Ffile-type-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Ffile-type-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Ffile-type-stream/lists"}