@datastream/file
Advanced tools
+23
| // Copyright 2026 will Farrell, and datastream contributors. | ||
| // SPDX-License-Identifier: MIT | ||
| import type { StreamOptions } from "@datastream/core"; | ||
| export interface FilePickerTypes { | ||
| description?: string; | ||
| accept?: Record<string, string[]>; | ||
| } | ||
| export function fileReadStream( | ||
| options: { | ||
| types?: FilePickerTypes[]; | ||
| }, | ||
| streamOptions?: StreamOptions, | ||
| ): Promise<unknown>; | ||
| export function fileWriteStream( | ||
| options: { | ||
| path?: string; | ||
| types?: FilePickerTypes[]; | ||
| }, | ||
| streamOptions?: StreamOptions, | ||
| ): Promise<unknown>; |
+52
| <div align="center"> | ||
| <h1><datastream> `file`</h1> | ||
| <img alt="datastream logo" src="https://raw.githubusercontent.com/willfarrell/datastream/main/docs/img/datastream-logo.svg"/> | ||
| <p><strong>File system streams.</strong></p> | ||
| <p> | ||
| <a href="https://github.com/willfarrell/datastream/actions/workflows/test-unit.yml"><img src="https://github.com/willfarrell/datastream/actions/workflows/test-unit.yml/badge.svg" alt="GitHub Actions unit test status"></a> | ||
| <a href="https://github.com/willfarrell/datastream/actions/workflows/test-dast.yml"><img src="https://github.com/willfarrell/datastream/actions/workflows/test-dast.yml/badge.svg" alt="GitHub Actions dast test status"></a> | ||
| <a href="https://github.com/willfarrell/datastream/actions/workflows/test-perf.yml"><img src="https://github.com/willfarrell/datastream/actions/workflows/test-perf.yml/badge.svg" alt="GitHub Actions perf test status"></a> | ||
| <a href="https://github.com/willfarrell/datastream/actions/workflows/test-sast.yml"><img src="https://github.com/willfarrell/datastream/actions/workflows/test-sast.yml/badge.svg" alt="GitHub Actions SAST test status"></a> | ||
| <a href="https://github.com/willfarrell/datastream/actions/workflows/test-lint.yml"><img src="https://github.com/willfarrell/datastream/actions/workflows/test-lint.yml/badge.svg" alt="GitHub Actions lint test status"></a> | ||
| <br/> | ||
| <a href="https://www.npmjs.com/package/@datastream/file"><img alt="npm version" src="https://img.shields.io/npm/v/@datastream/file.svg"></a> | ||
| <a href="https://packagephobia.com/result?p=@datastream/file"><img src="https://packagephobia.com/badge?p=@datastream/file" alt="npm install size"></a> | ||
| <a href="https://www.npmjs.com/package/@datastream/file"> | ||
| <img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@datastream/file.svg"></a> | ||
| <a href="https://www.npmjs.com/package/@datastream/file#provenance"> | ||
| <img alt="npm provenance" src="https://img.shields.io/badge/provenance-Yes-brightgreen"></a> | ||
| <br/> | ||
| <a href="https://scorecard.dev/viewer/?uri=github.com/willfarrell/datastream"><img src="https://api.scorecard.dev/projects/github.com/willfarrell/datastream/badge" alt="Open Source Security Foundation (OpenSSF) Scorecard"></a> | ||
| <a href="https://slsa.dev"><img src="https://slsa.dev/images/gh-badge-level3.svg" alt="SLSA 3"></a> | ||
| <a href="https://github.com/willfarrell/datastream/blob/main/docs/CODE_OF_CONDUCT.md"><img src="https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg"></a> | ||
| <a href="https://biomejs.dev"><img alt="Checked with Biome" src="https://img.shields.io/badge/Checked_with-Biome-60a5fa?style=flat&logo=biome"></a> | ||
| <a href="https://conventionalcommits.org"><img alt="Conventional Commits" src="https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white"></a> | ||
| <a href="https://github.com/willfarrell/datastream/blob/main/package.json#L32"> | ||
| <img alt="code coverage" src="https://img.shields.io/badge/code%20coverage-95%25-brightgreen"></a> | ||
| </p> | ||
| <p>You can read the documentation at: <a href="https://datastream.js.org">https://datastream.js.org</a></p> | ||
| </div> | ||
| ## Install | ||
| To install datastream you can use NPM: | ||
| ```bash | ||
| npm install --save @datastream/file | ||
| ``` | ||
| ## Documentation and examples | ||
| For documentation and examples, refer to the main [datastream monorepo on GitHub](https://github.com/willfarrell/datastream) or [datastream official website](https://datastream.js.org). | ||
| ## Contributing | ||
| Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/willfarrell/datastream/issues) or to [submit Pull Requests](https://github.com/willfarrell/datastream/pulls). | ||
| ## License | ||
| Licensed under [MIT License](LICENSE). Copyright (c) 2026 [will Farrell](https://github.com/willfarrell), and [datastream contributors](https://github.com/willfarrell/datastream/graphs/contributors). |
+1
-1
@@ -24,3 +24,3 @@ import { createReadStream, createWriteStream } from "node:fs"; | ||
| if (types.length) { | ||
| throw new Error("invalid extension"); | ||
| throw new Error("Invalid extension"); | ||
| } | ||
@@ -27,0 +27,0 @@ }; |
| { | ||
| "version": 3, | ||
| "sources": ["index.node.js"], | ||
| "sourcesContent": ["import { createReadStream, createWriteStream } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { makeOptions } from \"@datastream/core\";\n\nexport const fileReadStream = ({ path, types }, streamOptions = {}) => {\n\tenforceType(path, types);\n\treturn createReadStream(path, makeOptions(streamOptions));\n};\n\nexport const fileWriteStream = ({ path, types }, streamOptions = {}) => {\n\tenforceType(path, types);\n\treturn createWriteStream(path, makeOptions(streamOptions));\n};\n\nconst enforceType = (path, types = []) => {\n\tconst pathExt = extname(path);\n\tfor (const type of types) {\n\t\tfor (const mime in type.accept) {\n\t\t\tfor (const ext of type.accept[mime]) {\n\t\t\t\tif (pathExt === ext) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (types.length) {\n\t\tthrow new Error(\"invalid extension\");\n\t}\n};\n\nexport default {\n\treadStream: fileReadStream,\n\twriteStream: fileWriteStream,\n};\n"], | ||
| "mappings": "AAAA,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAErB,MAAM,iBAAiB,CAAC,EAAE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;AACtE,cAAY,MAAM,KAAK;AACvB,SAAO,iBAAiB,MAAM,YAAY,aAAa,CAAC;AACzD;AAEO,MAAM,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;AACvE,cAAY,MAAM,KAAK;AACvB,SAAO,kBAAkB,MAAM,YAAY,aAAa,CAAC;AAC1D;AAEA,MAAM,cAAc,CAAC,MAAM,QAAQ,CAAC,MAAM;AACzC,QAAM,UAAU,QAAQ,IAAI;AAC5B,aAAW,QAAQ,OAAO;AACzB,eAAW,QAAQ,KAAK,QAAQ;AAC/B,iBAAW,OAAO,KAAK,OAAO,IAAI,GAAG;AACpC,YAAI,YAAY,KAAK;AACpB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,MAAI,MAAM,QAAQ;AACjB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AACD;AAEA,IAAO,qBAAQ;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AACd;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createReadStream, createWriteStream } from \"node:fs\";\nimport { extname } from \"node:path\";\nimport { makeOptions } from \"@datastream/core\";\n\nexport const fileReadStream = ({ path, types }, streamOptions = {}) => {\n\tenforceType(path, types);\n\treturn createReadStream(path, makeOptions(streamOptions));\n};\n\nexport const fileWriteStream = ({ path, types }, streamOptions = {}) => {\n\tenforceType(path, types);\n\treturn createWriteStream(path, makeOptions(streamOptions));\n};\n\nconst enforceType = (path, types = []) => {\n\tconst pathExt = extname(path);\n\tfor (const type of types) {\n\t\tfor (const mime in type.accept) {\n\t\t\tfor (const ext of type.accept[mime]) {\n\t\t\t\tif (pathExt === ext) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif (types.length) {\n\t\tthrow new Error(\"Invalid extension\");\n\t}\n};\n\nexport default {\n\treadStream: fileReadStream,\n\twriteStream: fileWriteStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAErB,MAAM,iBAAiB,CAAC,EAAE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;AACtE,cAAY,MAAM,KAAK;AACvB,SAAO,iBAAiB,MAAM,YAAY,aAAa,CAAC;AACzD;AAEO,MAAM,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM;AACvE,cAAY,MAAM,KAAK;AACvB,SAAO,kBAAkB,MAAM,YAAY,aAAa,CAAC;AAC1D;AAEA,MAAM,cAAc,CAAC,MAAM,QAAQ,CAAC,MAAM;AACzC,QAAM,UAAU,QAAQ,IAAI;AAC5B,aAAW,QAAQ,OAAO;AACzB,eAAW,QAAQ,KAAK,QAAQ;AAC/B,iBAAW,OAAO,KAAK,OAAO,IAAI,GAAG;AACpC,YAAI,YAAY,KAAK;AACpB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,MAAI,MAAM,QAAQ;AACjB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACpC;AACD;AAEA,IAAO,qBAAQ;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AACd;", | ||
| "names": [] | ||
| } |
| { | ||
| "version": 3, | ||
| "sources": ["index.web.js"], | ||
| "sourcesContent": ["import { createReadableStream } from \"@datastream/core\";\n\nexport const fileReadStream = async ({ types }, _streamOptions = {}) => {\n\tconst [fileHandle] = await window.showOpenFilePicker({ types });\n\tconst fileData = await fileHandle.getFile();\n\treturn createReadableStream(fileData);\n};\n\nexport const fileWriteStream = async ({ path, types }, _streamOptions = {}) => {\n\tconst fileHandle = await window.showSaveFilePicker({\n\t\tsuggestedName: path,\n\t\ttypes,\n\t});\n\treturn fileHandle.createWritable();\n};\n\nexport default {\n\treadStream: fileReadStream,\n\twriteStream: fileWriteStream,\n};\n"], | ||
| "mappings": "AAAA,SAAS,4BAA4B;AAE9B,MAAM,iBAAiB,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM;AACvE,QAAM,CAAC,UAAU,IAAI,MAAM,OAAO,mBAAmB,EAAE,MAAM,CAAC;AAC9D,QAAM,WAAW,MAAM,WAAW,QAAQ;AAC1C,SAAO,qBAAqB,QAAQ;AACrC;AAEO,MAAM,kBAAkB,OAAO,EAAE,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM;AAC9E,QAAM,aAAa,MAAM,OAAO,mBAAmB;AAAA,IAClD,eAAe;AAAA,IACf;AAAA,EACD,CAAC;AACD,SAAO,WAAW,eAAe;AAClC;AAEA,IAAO,oBAAQ;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AACd;", | ||
| "sourcesContent": ["// Copyright 2026 will Farrell, and datastream contributors.\n// SPDX-License-Identifier: MIT\nimport { createReadableStream } from \"@datastream/core\";\n\nexport const fileReadStream = async ({ types }, _streamOptions = {}) => {\n\tconst [fileHandle] = await window.showOpenFilePicker({ types });\n\tconst fileData = await fileHandle.getFile();\n\treturn createReadableStream(fileData);\n};\n\nexport const fileWriteStream = async ({ path, types }, _streamOptions = {}) => {\n\tconst fileHandle = await window.showSaveFilePicker({\n\t\tsuggestedName: path,\n\t\ttypes,\n\t});\n\treturn fileHandle.createWritable();\n};\n\nexport default {\n\treadStream: fileReadStream,\n\twriteStream: fileWriteStream,\n};\n"], | ||
| "mappings": "AAEA,SAAS,4BAA4B;AAE9B,MAAM,iBAAiB,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAAC,MAAM;AACvE,QAAM,CAAC,UAAU,IAAI,MAAM,OAAO,mBAAmB,EAAE,MAAM,CAAC;AAC9D,QAAM,WAAW,MAAM,WAAW,QAAQ;AAC1C,SAAO,qBAAqB,QAAQ;AACrC;AAEO,MAAM,kBAAkB,OAAO,EAAE,MAAM,MAAM,GAAG,iBAAiB,CAAC,MAAM;AAC9E,QAAM,aAAa,MAAM,OAAO,mBAAmB;AAAA,IAClD,eAAe;AAAA,IACf;AAAA,EACD,CAAC;AACD,SAAO,WAAW,eAAe;AAClC;AAEA,IAAO,oBAAQ;AAAA,EACd,YAAY;AAAA,EACZ,aAAa;AACd;", | ||
| "names": [] | ||
| } |
+6
-13
| { | ||
| "name": "@datastream/file", | ||
| "version": "0.0.42", | ||
| "description": "", | ||
| "version": "0.1.4", | ||
| "description": "File system readable and writable streams with extension type enforcement", | ||
| "type": "module", | ||
@@ -13,3 +13,3 @@ "engines": { | ||
| }, | ||
| "main": "./index.web.mjs", | ||
| "main": "./index.node.mjs", | ||
| "module": "./index.web.mjs", | ||
@@ -22,6 +22,2 @@ "exports": { | ||
| "default": "./index.node.mjs" | ||
| }, | ||
| "__require": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.node.cjs" | ||
| } | ||
@@ -42,3 +38,2 @@ }, | ||
| "*.mjs", | ||
| "*.cjs", | ||
| "*.map", | ||
@@ -64,3 +59,3 @@ "*.d.ts" | ||
| "url": "github:willfarrell/datastream", | ||
| "directory": "packages/digest" | ||
| "directory": "packages/file" | ||
| }, | ||
@@ -72,6 +67,4 @@ "bugs": { | ||
| "dependencies": { | ||
| "@datastream/core": "0.0.42", | ||
| "@datastream/file": "0.0.42" | ||
| }, | ||
| "gitHead": "6ddc0fadabf5f3702a51aebae1fc6b252c6ae8d4" | ||
| "@datastream/core": "0.1.4" | ||
| } | ||
| } |
| var __defProp = Object.defineProperty; | ||
| var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
| var __getOwnPropNames = Object.getOwnPropertyNames; | ||
| var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| }; | ||
| var __copyProps = (to, from, except, desc) => { | ||
| if ((from && typeof from === "object") || typeof from === "function") { | ||
| for (const key of __getOwnPropNames(from)) | ||
| if (!__hasOwnProp.call(to, key) && key !== except) | ||
| __defProp(to, key, { | ||
| get: () => from[key], | ||
| enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable, | ||
| }); | ||
| } | ||
| return to; | ||
| }; | ||
| var __toCommonJS = (mod) => | ||
| __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var index_node_exports = {}; | ||
| __export(index_node_exports, { | ||
| default: () => index_node_default, | ||
| fileReadStream: () => fileReadStream, | ||
| fileWriteStream: () => fileWriteStream, | ||
| }); | ||
| module.exports = __toCommonJS(index_node_exports); | ||
| var import_node_path = require("node:path"); | ||
| var import_node_fs = require("node:fs"); | ||
| var import_core = require("@datastream/core"); | ||
| const fileReadStream = ({ path, types }, streamOptions) => { | ||
| enforceType(path, types); | ||
| return (0, import_node_fs.createReadStream)( | ||
| path, | ||
| (0, import_core.makeOptions)(streamOptions), | ||
| ); | ||
| }; | ||
| const fileWriteStream = ({ path, types }, streamOptions) => { | ||
| enforceType(path, types); | ||
| return (0, import_node_fs.createWriteStream)( | ||
| path, | ||
| (0, import_core.makeOptions)(streamOptions), | ||
| ); | ||
| }; | ||
| const enforceType = (path, types = []) => { | ||
| const pathExt = (0, import_node_path.extname)(path); | ||
| for (const type of types) { | ||
| for (const mime in type.accept) { | ||
| for (const ext of type.accept[mime]) { | ||
| if (pathExt === ext) { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if (types.length) { | ||
| throw new Error("invalid extension"); | ||
| } | ||
| }; | ||
| var index_node_default = { | ||
| readStream: fileReadStream, | ||
| writeStream: fileWriteStream, | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && | ||
| (module.exports = { | ||
| fileReadStream, | ||
| fileWriteStream, | ||
| }); |
| { | ||
| "version": 3, | ||
| "sources": ["index.node.js"], | ||
| "sourcesContent": ["import { extname } from 'node:path'\nimport { createReadStream, createWriteStream } from 'node:fs'\nimport { makeOptions } from '@datastream/core'\n\nexport const fileReadStream = ({ path, types }, streamOptions) => {\n enforceType(path, types)\n return createReadStream(path, makeOptions(streamOptions))\n}\n\nexport const fileWriteStream = ({ path, types }, streamOptions) => {\n enforceType(path, types)\n return createWriteStream(path, makeOptions(streamOptions))\n}\n\nconst enforceType = (path, types = []) => {\n const pathExt = extname(path)\n for (const type of types) {\n for (const mime in type.accept) {\n for (const ext of type.accept[mime]) {\n if (pathExt === ext) {\n return\n }\n }\n }\n }\n if (types.length) {\n throw new Error('invalid extension')\n }\n}\n\nexport default {\n readStream: fileReadStream,\n writeStream: fileWriteStream\n}\n"], | ||
| "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAwB;AACxB,qBAAoD;AACpD,kBAA4B;AAErB,MAAM,iBAAiB,CAAC,EAAE,MAAM,MAAM,GAAG,kBAAkB;AAChE,cAAY,MAAM,KAAK;AACvB,aAAO,iCAAiB,UAAM,yBAAY,aAAa,CAAC;AAC1D;AAEO,MAAM,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAAG,kBAAkB;AACjE,cAAY,MAAM,KAAK;AACvB,aAAO,kCAAkB,UAAM,yBAAY,aAAa,CAAC;AAC3D;AAEA,MAAM,cAAc,CAAC,MAAM,QAAQ,CAAC,MAAM;AACxC,QAAM,cAAU,0BAAQ,IAAI;AAC5B,aAAW,QAAQ,OAAO;AACxB,eAAW,QAAQ,KAAK,QAAQ;AAC9B,iBAAW,OAAO,KAAK,OAAO,OAAO;AACnC,YAAI,YAAY,KAAK;AACnB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,MAAI,MAAM,QAAQ;AAChB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AACF;AAEA,IAAO,qBAAQ;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AACf;", | ||
| "names": [] | ||
| } |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
10384
7.42%1
-50%1
-50%52
Infinity%77
-39.37%+ Added
- Removed
- Removed
Updated