@datastream/file
Advanced tools
+46
-35
@@ -6,19 +6,23 @@ var __defProp = Object.defineProperty; | ||
| var __export = (target, all) => { | ||
| for (var name in all) | ||
| __defProp(target, name, { get: all[name], enumerable: true }); | ||
| 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 (let 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; | ||
| 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 __toCommonJS = (mod) => | ||
| __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
| var index_node_exports = {}; | ||
| __export(index_node_exports, { | ||
| default: () => index_node_default, | ||
| fileReadStream: () => fileReadStream, | ||
| fileWriteStream: () => fileWriteStream | ||
| default: () => index_node_default, | ||
| fileReadStream: () => fileReadStream, | ||
| fileWriteStream: () => fileWriteStream, | ||
| }); | ||
@@ -30,32 +34,39 @@ module.exports = __toCommonJS(index_node_exports); | ||
| const fileReadStream = ({ path, types }, streamOptions) => { | ||
| enforceType(path, types); | ||
| return (0, import_node_fs.createReadStream)(path, (0, import_core.makeOptions)(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)); | ||
| 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"); | ||
| } | ||
| 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 | ||
| readStream: fileReadStream, | ||
| writeStream: fileWriteStream, | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
| 0 && (module.exports = { | ||
| fileReadStream, | ||
| fileWriteStream | ||
| }); | ||
| 0 && | ||
| (module.exports = { | ||
| fileReadStream, | ||
| fileWriteStream, | ||
| }); |
+3
-3
@@ -0,9 +1,9 @@ | ||
| import { createReadStream, createWriteStream } from "node:fs"; | ||
| import { extname } from "node:path"; | ||
| import { createReadStream, createWriteStream } from "node:fs"; | ||
| import { makeOptions } from "@datastream/core"; | ||
| const fileReadStream = ({ path, types }, streamOptions) => { | ||
| const fileReadStream = ({ path, types }, streamOptions = {}) => { | ||
| enforceType(path, types); | ||
| return createReadStream(path, makeOptions(streamOptions)); | ||
| }; | ||
| const fileWriteStream = ({ path, types }, streamOptions) => { | ||
| const fileWriteStream = ({ path, types }, streamOptions = {}) => { | ||
| enforceType(path, types); | ||
@@ -10,0 +10,0 @@ return createWriteStream(path, makeOptions(streamOptions)); |
| { | ||
| "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,SAAS,eAAe;AACxB,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,mBAAmB;AAErB,MAAM,iBAAiB,CAAC,EAAE,MAAM,MAAM,GAAG,kBAAkB;AAChE,cAAY,MAAM,KAAK;AACvB,SAAO,iBAAiB,MAAM,YAAY,aAAa,CAAC;AAC1D;AAEO,MAAM,kBAAkB,CAAC,EAAE,MAAM,MAAM,GAAG,kBAAkB;AACjE,cAAY,MAAM,KAAK;AACvB,SAAO,kBAAkB,MAAM,YAAY,aAAa,CAAC;AAC3D;AAEA,MAAM,cAAc,CAAC,MAAM,QAAQ,CAAC,MAAM;AACxC,QAAM,UAAU,QAAQ,IAAI;AAC5B,aAAW,QAAQ,OAAO;AACxB,eAAW,QAAQ,KAAK,QAAQ;AAC9B,iBAAW,OAAO,KAAK,OAAO,IAAI,GAAG;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;", | ||
| "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;", | ||
| "names": [] | ||
| } |
+2
-2
| import { createReadableStream } from "@datastream/core"; | ||
| const fileReadStream = async ({ types }, streamOptions) => { | ||
| const fileReadStream = async ({ types }, _streamOptions = {}) => { | ||
| const [fileHandle] = await window.showOpenFilePicker({ types }); | ||
@@ -7,3 +7,3 @@ const fileData = await fileHandle.getFile(); | ||
| }; | ||
| const fileWriteStream = async ({ path, types }, streamOptions) => { | ||
| const fileWriteStream = async ({ path, types }, _streamOptions = {}) => { | ||
| const fileHandle = await window.showSaveFilePicker({ | ||
@@ -10,0 +10,0 @@ suggestedName: path, |
| { | ||
| "version": 3, | ||
| "sources": ["index.web.js"], | ||
| "sourcesContent": ["import { createReadableStream } from '@datastream/core'\n\nexport const fileReadStream = async ({ types }, streamOptions) => {\n const [fileHandle] = await window.showOpenFilePicker({ types })\n const fileData = await fileHandle.getFile()\n return createReadableStream(fileData)\n}\n\nexport const fileWriteStream = async ({ path, types }, streamOptions) => {\n const fileHandle = await window.showSaveFilePicker({\n suggestedName: path,\n types\n })\n return fileHandle.createWritable()\n}\n\nexport default {\n readStream: fileReadStream,\n writeStream: fileWriteStream\n}\n"], | ||
| "mappings": "AAAA,SAAS,4BAA4B;AAE9B,MAAM,iBAAiB,OAAO,EAAE,MAAM,GAAG,kBAAkB;AAChE,QAAM,CAAC,UAAU,IAAI,MAAM,OAAO,mBAAmB,EAAE,MAAM,CAAC;AAC9D,QAAM,WAAW,MAAM,WAAW,QAAQ;AAC1C,SAAO,qBAAqB,QAAQ;AACtC;AAEO,MAAM,kBAAkB,OAAO,EAAE,MAAM,MAAM,GAAG,kBAAkB;AACvE,QAAM,aAAa,MAAM,OAAO,mBAAmB;AAAA,IACjD,eAAe;AAAA,IACf;AAAA,EACF,CAAC;AACD,SAAO,WAAW,eAAe;AACnC;AAEA,IAAO,oBAAQ;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AACf;", | ||
| "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;", | ||
| "names": [] | ||
| } |
+70
-70
| { | ||
| "name": "@datastream/file", | ||
| "version": "0.0.40", | ||
| "description": "", | ||
| "type": "module", | ||
| "engines": { | ||
| "node": ">=18" | ||
| }, | ||
| "engineStrict": true, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "main": "./index.web.mjs", | ||
| "module": "./index.web.mjs", | ||
| "exports": { | ||
| ".": { | ||
| "node": { | ||
| "webstream": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.web.mjs" | ||
| }, | ||
| "import": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.node.mjs" | ||
| }, | ||
| "__require": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.node.cjs" | ||
| } | ||
| }, | ||
| "import": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.web.mjs" | ||
| } | ||
| } | ||
| }, | ||
| "types": "index.d.ts", | ||
| "files": [ | ||
| "*.mjs", | ||
| "*.cjs", | ||
| "*.map", | ||
| "*.d.ts" | ||
| ], | ||
| "scripts": { | ||
| "test": "npm run test:unit", | ||
| "test:unit": "node --test", | ||
| "test:benchmark": "node __benchmarks__/index.js" | ||
| }, | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "Web Stream API", | ||
| "Node Stream API" | ||
| ], | ||
| "author": { | ||
| "name": "datastream contributors", | ||
| "url": "https://github.com/willfarrell/datastream/graphs/contributors" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "github:willfarrell/datastream", | ||
| "directory": "packages/digest" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/willfarrell/datastream/issues" | ||
| }, | ||
| "homepage": "https://datastream.js.org", | ||
| "dependencies": { | ||
| "@datastream/core": "0.0.40", | ||
| "@datastream/file": "0.0.40" | ||
| }, | ||
| "gitHead": "4dbeb8efee8daea0f19b14573f064afc77499094" | ||
| "name": "@datastream/file", | ||
| "version": "0.0.41", | ||
| "description": "", | ||
| "type": "module", | ||
| "engines": { | ||
| "node": ">=22" | ||
| }, | ||
| "engineStrict": true, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "main": "./index.web.mjs", | ||
| "module": "./index.web.mjs", | ||
| "exports": { | ||
| ".": { | ||
| "node": { | ||
| "import": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.node.mjs" | ||
| }, | ||
| "__require": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.node.cjs" | ||
| } | ||
| }, | ||
| "import": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.web.mjs" | ||
| } | ||
| }, | ||
| "./webstream": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.web.mjs" | ||
| } | ||
| }, | ||
| "types": "index.d.ts", | ||
| "files": [ | ||
| "*.mjs", | ||
| "*.cjs", | ||
| "*.map", | ||
| "*.d.ts" | ||
| ], | ||
| "scripts": { | ||
| "test": "npm run test:unit", | ||
| "test:unit": "node --test", | ||
| "test:benchmark": "node __benchmarks__/index.js" | ||
| }, | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "Web Stream API", | ||
| "Node Stream API" | ||
| ], | ||
| "author": { | ||
| "name": "datastream contributors", | ||
| "url": "https://github.com/willfarrell/datastream/graphs/contributors" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "github:willfarrell/datastream", | ||
| "directory": "packages/digest" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/willfarrell/datastream/issues" | ||
| }, | ||
| "homepage": "https://datastream.js.org", | ||
| "dependencies": { | ||
| "@datastream/core": "0.0.41", | ||
| "@datastream/file": "0.0.41" | ||
| }, | ||
| "gitHead": "6ddc0fadabf5f3702a51aebae1fc6b252c6ae8d4" | ||
| } |
| import { createReadableStream } from "@datastream/core"; | ||
| const fileReadStream = async ({ types }, streamOptions) => { | ||
| const [fileHandle] = await window.showOpenFilePicker({ types }); | ||
| const fileData = await fileHandle.getFile(); | ||
| return createReadableStream(fileData); | ||
| }; | ||
| const fileWriteStream = async ({ path, types }, streamOptions) => { | ||
| const fileHandle = await window.showSaveFilePicker({ | ||
| suggestedName: path, | ||
| types | ||
| }); | ||
| return fileHandle.createWritable(); | ||
| }; | ||
| var index_web_default = { | ||
| readStream: fileReadStream, | ||
| writeStream: fileWriteStream | ||
| }; | ||
| export { | ||
| index_web_default as default, | ||
| fileReadStream, | ||
| fileWriteStream | ||
| }; |
-21
| MIT License | ||
| Copyright (c) 2022 will Farrell | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
9667
-15.45%7
-22.22%127
-7.97%+ Added
- Removed
Updated
Updated