@datastream/file 0.0.42 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/index.d.ts +23 -0
- package/index.node.mjs +1 -1
- package/index.node.mjs.map +2 -2
- package/index.web.mjs.map +2 -2
- package/package.json +6 -13
- package/index.node.cjs +0 -70
- package/index.node.cjs.map +0 -7
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1><datastream> `file`</h1>
|
|
3
|
+
<img alt="datastream logo" src="https://raw.githubusercontent.com/willfarrell/datastream/main/docs/img/datastream-logo.svg"/>
|
|
4
|
+
<p><strong>File system streams.</strong></p>
|
|
5
|
+
<p>
|
|
6
|
+
<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>
|
|
7
|
+
<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>
|
|
8
|
+
<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>
|
|
9
|
+
<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>
|
|
10
|
+
<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>
|
|
11
|
+
<br/>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@datastream/file"><img alt="npm version" src="https://img.shields.io/npm/v/@datastream/file.svg"></a>
|
|
13
|
+
<a href="https://packagephobia.com/result?p=@datastream/file"><img src="https://packagephobia.com/badge?p=@datastream/file" alt="npm install size"></a>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@datastream/file">
|
|
15
|
+
<img alt="npm weekly downloads" src="https://img.shields.io/npm/dw/@datastream/file.svg"></a>
|
|
16
|
+
<a href="https://www.npmjs.com/package/@datastream/file#provenance">
|
|
17
|
+
<img alt="npm provenance" src="https://img.shields.io/badge/provenance-Yes-brightgreen"></a>
|
|
18
|
+
<br/>
|
|
19
|
+
<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>
|
|
20
|
+
<a href="https://slsa.dev"><img src="https://slsa.dev/images/gh-badge-level3.svg" alt="SLSA 3"></a>
|
|
21
|
+
<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>
|
|
22
|
+
<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>
|
|
23
|
+
<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>
|
|
24
|
+
<a href="https://github.com/willfarrell/datastream/blob/main/package.json#L32">
|
|
25
|
+
<img alt="code coverage" src="https://img.shields.io/badge/code%20coverage-95%25-brightgreen"></a>
|
|
26
|
+
</p>
|
|
27
|
+
<p>You can read the documentation at: <a href="https://datastream.js.org">https://datastream.js.org</a></p>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
To install datastream you can use NPM:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install --save @datastream/file
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Documentation and examples
|
|
41
|
+
|
|
42
|
+
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).
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Contributing
|
|
46
|
+
|
|
47
|
+
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).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2026 [will Farrell](https://github.com/willfarrell), and [datastream contributors](https://github.com/willfarrell/datastream/graphs/contributors).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2026 will Farrell, and datastream contributors.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
import type { StreamOptions } from "@datastream/core";
|
|
4
|
+
|
|
5
|
+
export interface FilePickerTypes {
|
|
6
|
+
description?: string;
|
|
7
|
+
accept?: Record<string, string[]>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function fileReadStream(
|
|
11
|
+
options: {
|
|
12
|
+
types?: FilePickerTypes[];
|
|
13
|
+
},
|
|
14
|
+
streamOptions?: StreamOptions,
|
|
15
|
+
): Promise<unknown>;
|
|
16
|
+
|
|
17
|
+
export function fileWriteStream(
|
|
18
|
+
options: {
|
|
19
|
+
path?: string;
|
|
20
|
+
types?: FilePickerTypes[];
|
|
21
|
+
},
|
|
22
|
+
streamOptions?: StreamOptions,
|
|
23
|
+
): Promise<unknown>;
|
package/index.node.mjs
CHANGED
package/index.node.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.node.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"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"],
|
|
5
|
+
"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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/index.web.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["index.web.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"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"],
|
|
5
|
+
"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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datastream/file",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "File system readable and writable streams with extension type enforcement",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
|
-
"main": "./index.
|
|
13
|
+
"main": "./index.node.mjs",
|
|
14
14
|
"module": "./index.web.mjs",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
@@ -18,10 +18,6 @@
|
|
|
18
18
|
"import": {
|
|
19
19
|
"types": "./index.d.ts",
|
|
20
20
|
"default": "./index.node.mjs"
|
|
21
|
-
},
|
|
22
|
-
"__require": {
|
|
23
|
-
"types": "./index.d.ts",
|
|
24
|
-
"default": "./index.node.cjs"
|
|
25
21
|
}
|
|
26
22
|
},
|
|
27
23
|
"import": {
|
|
@@ -37,7 +33,6 @@
|
|
|
37
33
|
"types": "index.d.ts",
|
|
38
34
|
"files": [
|
|
39
35
|
"*.mjs",
|
|
40
|
-
"*.cjs",
|
|
41
36
|
"*.map",
|
|
42
37
|
"*.d.ts"
|
|
43
38
|
],
|
|
@@ -58,15 +53,13 @@
|
|
|
58
53
|
"repository": {
|
|
59
54
|
"type": "git",
|
|
60
55
|
"url": "github:willfarrell/datastream",
|
|
61
|
-
"directory": "packages/
|
|
56
|
+
"directory": "packages/file"
|
|
62
57
|
},
|
|
63
58
|
"bugs": {
|
|
64
59
|
"url": "https://github.com/willfarrell/datastream/issues"
|
|
65
60
|
},
|
|
66
61
|
"homepage": "https://datastream.js.org",
|
|
67
62
|
"dependencies": {
|
|
68
|
-
"@datastream/core": "0.
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
"gitHead": "6ddc0fadabf5f3702a51aebae1fc6b252c6ae8d4"
|
|
63
|
+
"@datastream/core": "0.1.4"
|
|
64
|
+
}
|
|
72
65
|
}
|
package/index.node.cjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if ((from && typeof from === "object") || typeof from === "function") {
|
|
11
|
-
for (const key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, {
|
|
14
|
-
get: () => from[key],
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toCommonJS = (mod) =>
|
|
21
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
-
var index_node_exports = {};
|
|
23
|
-
__export(index_node_exports, {
|
|
24
|
-
default: () => index_node_default,
|
|
25
|
-
fileReadStream: () => fileReadStream,
|
|
26
|
-
fileWriteStream: () => fileWriteStream,
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_node_exports);
|
|
29
|
-
var import_node_path = require("node:path");
|
|
30
|
-
var import_node_fs = require("node:fs");
|
|
31
|
-
var import_core = require("@datastream/core");
|
|
32
|
-
const fileReadStream = ({ path, types }, streamOptions) => {
|
|
33
|
-
enforceType(path, types);
|
|
34
|
-
return (0, import_node_fs.createReadStream)(
|
|
35
|
-
path,
|
|
36
|
-
(0, import_core.makeOptions)(streamOptions),
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
const fileWriteStream = ({ path, types }, streamOptions) => {
|
|
40
|
-
enforceType(path, types);
|
|
41
|
-
return (0, import_node_fs.createWriteStream)(
|
|
42
|
-
path,
|
|
43
|
-
(0, import_core.makeOptions)(streamOptions),
|
|
44
|
-
);
|
|
45
|
-
};
|
|
46
|
-
const enforceType = (path, types = []) => {
|
|
47
|
-
const pathExt = (0, import_node_path.extname)(path);
|
|
48
|
-
for (const type of types) {
|
|
49
|
-
for (const mime in type.accept) {
|
|
50
|
-
for (const ext of type.accept[mime]) {
|
|
51
|
-
if (pathExt === ext) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (types.length) {
|
|
58
|
-
throw new Error("invalid extension");
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var index_node_default = {
|
|
62
|
-
readStream: fileReadStream,
|
|
63
|
-
writeStream: fileWriteStream,
|
|
64
|
-
};
|
|
65
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
-
0 &&
|
|
67
|
-
(module.exports = {
|
|
68
|
-
fileReadStream,
|
|
69
|
-
fileWriteStream,
|
|
70
|
-
});
|
package/index.node.cjs.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["index.node.js"],
|
|
4
|
-
"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"],
|
|
5
|
-
"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;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|