@environment-safe/file 0.0.1
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/.babelrc.cjs +18 -0
- package/.eslintrc.cjs +42 -0
- package/.husky/pre-commit +11 -0
- package/.import-config.json +5 -0
- package/.jsdoc.json +15 -0
- package/LICENSE +20 -0
- package/README.md +95 -0
- package/containers/development.dockerfile +11 -0
- package/containers/production.dockerfile +11 -0
- package/containers/test.dockerfile +11 -0
- package/dist/buffer.cjs +77 -0
- package/dist/index.cjs +599 -0
- package/index.html +74 -0
- package/package.json +107 -0
- package/src/buffer.mjs +73 -0
- package/src/index.mjs +599 -0
- package/test/index.html +443 -0
- package/test/lauch-insecure-chrome +20 -0
- package/test/test.cjs +10 -0
- package/test/test.mjs +59 -0
package/.babelrc.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"plugins": [
|
|
3
|
+
["@babel/plugin-transform-modules-commonjs"],
|
|
4
|
+
["babel-plugin-transform-import-meta"],
|
|
5
|
+
[ "search-and-replace", {
|
|
6
|
+
"rules": [
|
|
7
|
+
{
|
|
8
|
+
"search": /\.mjs/,
|
|
9
|
+
"replace": ".cjs"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"search": /\.\/src\//,
|
|
13
|
+
"replace": "./dist/"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}]
|
|
17
|
+
]
|
|
18
|
+
}
|
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
'env': {
|
|
3
|
+
'browser': true,
|
|
4
|
+
'commonjs': true,
|
|
5
|
+
'es2021': true
|
|
6
|
+
},
|
|
7
|
+
'globals': {
|
|
8
|
+
'process': 'readonly',
|
|
9
|
+
'define': 'readonly'
|
|
10
|
+
},
|
|
11
|
+
'extends': 'eslint:recommended',
|
|
12
|
+
'overrides': [
|
|
13
|
+
],
|
|
14
|
+
'parserOptions': {
|
|
15
|
+
'ecmaVersion': 'latest',
|
|
16
|
+
'sourceType': 'module'
|
|
17
|
+
},
|
|
18
|
+
'rules': {
|
|
19
|
+
'indent': [
|
|
20
|
+
'error',
|
|
21
|
+
4,
|
|
22
|
+
{ 'SwitchCase': 1 }
|
|
23
|
+
],
|
|
24
|
+
'linebreak-style': [
|
|
25
|
+
'error',
|
|
26
|
+
'unix'
|
|
27
|
+
],
|
|
28
|
+
'quotes': [
|
|
29
|
+
'error',
|
|
30
|
+
'single'
|
|
31
|
+
],
|
|
32
|
+
'semi': [
|
|
33
|
+
'error',
|
|
34
|
+
'always'
|
|
35
|
+
],
|
|
36
|
+
'no-unused-vars': [
|
|
37
|
+
'error', {
|
|
38
|
+
'args': 'none'
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
|
+
|
|
4
|
+
npm run lint
|
|
5
|
+
#npm run import-test
|
|
6
|
+
#npm run headless-browser-test
|
|
7
|
+
npm run build-commonjs
|
|
8
|
+
#npm run require-test
|
|
9
|
+
npm run build-docs
|
|
10
|
+
npm run build-types
|
|
11
|
+
npm run add-generated-files-to-commit
|
package/.jsdoc.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tags": {
|
|
3
|
+
"allowUnknownTags": true,
|
|
4
|
+
"dictionaries": ["jsdoc", "closure"]
|
|
5
|
+
},
|
|
6
|
+
"source": {
|
|
7
|
+
"include": ["."],
|
|
8
|
+
"includePattern": ".(mjs)$"
|
|
9
|
+
},
|
|
10
|
+
"plugins": [ "./node_modules/tsd-jsdoc/dist/plugin" ],
|
|
11
|
+
"opts": {
|
|
12
|
+
"template": "./node_modules/tsd-jsdoc/dist"
|
|
13
|
+
},
|
|
14
|
+
"sourceType": "module"
|
|
15
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2023 null.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
@environment-safe/file
|
|
2
|
+
======================
|
|
3
|
+
This is an experimental interface to provide a common file abstraction from client to server.
|
|
4
|
+
|
|
5
|
+
The design goal is to give the widest possible filesystem access, while minimizing the number of client interactions (via interaction initiation *or* popup) using a common API.
|
|
6
|
+
|
|
7
|
+
Usage
|
|
8
|
+
-----
|
|
9
|
+
|
|
10
|
+
### listing
|
|
11
|
+
|
|
12
|
+
You can list contents from an arbitrary location or from one of a few predefined locations (`desktop`, `documents`, `downloads`, `music`, `pictures`, `videos`). For example to list all the files in your `documents` directory:
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
const list = await File.list('documents', {
|
|
16
|
+
files: true,
|
|
17
|
+
directories: false
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You can load a file relative to the current directory, for example `foo.bar`
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const file = new File('foo.bar');
|
|
25
|
+
//or
|
|
26
|
+
const file = new File('foo.bar', '.');
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
You can load a file relative to the a predefined directory, for example `baz.mpg` in `videos`:
|
|
30
|
+
```javascript
|
|
31
|
+
const file = new File('baz.mpg', 'videos');
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
You can load a file relative to the a fully specified directory, for example `baz.info` in `/Users/me/`:
|
|
35
|
+
```javascript
|
|
36
|
+
const file = new File('baz.info', '/Users/me/');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can load a file relative to the a relative directory, for example `package.json` in `../node_modules/dep`:
|
|
40
|
+
```javascript
|
|
41
|
+
const file = new File('package.json', '../node_modules/dep');
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
You can load a file directly from a fully specified path:
|
|
45
|
+
```javascript
|
|
46
|
+
const file = new File('/Users/me/file.ext');
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Other scenarios may work in isolated circumstances, but are not supported client/server.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Roadmap
|
|
53
|
+
-------
|
|
54
|
+
|
|
55
|
+
- [ ] - test existing suite in windows + linux
|
|
56
|
+
- [ ] - safari directory returns
|
|
57
|
+
- [ ] - firefox directory returns
|
|
58
|
+
- [ ] - edge directory returns
|
|
59
|
+
- [ ] - apache directory returns
|
|
60
|
+
- [ ] - opera directory returns
|
|
61
|
+
- [ ] - streaming support
|
|
62
|
+
|
|
63
|
+
Testing
|
|
64
|
+
-------
|
|
65
|
+
|
|
66
|
+
Run the es module tests to test the root modules
|
|
67
|
+
```bash
|
|
68
|
+
npm run import-test
|
|
69
|
+
```
|
|
70
|
+
to run the same test inside the browser:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm run browser-test
|
|
74
|
+
```
|
|
75
|
+
to run the same test headless in chrome:
|
|
76
|
+
```bash
|
|
77
|
+
npm run headless-browser-test
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
to run the same test inside docker:
|
|
81
|
+
```bash
|
|
82
|
+
npm run container-test
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Run the commonjs tests against the `/dist` commonjs source (generated with the `build-commonjs` target).
|
|
86
|
+
```bash
|
|
87
|
+
npm run require-test
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Development
|
|
91
|
+
-----------
|
|
92
|
+
All work is done in the .mjs files and will be transpiled on commit to commonjs and tested.
|
|
93
|
+
|
|
94
|
+
If the above tests pass, then attempt a commit which will generate .d.ts files alongside the `src` files and commonjs classes in `dist`
|
|
95
|
+
|
package/dist/buffer.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FileBuffer = void 0;
|
|
7
|
+
var _browserOrNode = require("browser-or-node");
|
|
8
|
+
/* global Buffer:false */
|
|
9
|
+
/*
|
|
10
|
+
import { isBrowser, isJsDom } from 'browser-or-node';
|
|
11
|
+
import * as mod from 'module';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
let internalRequire = null;
|
|
14
|
+
if(typeof require !== 'undefined') internalRequire = require;
|
|
15
|
+
const ensureRequire = ()=> (!internalRequire) && (internalRequire = mod.createRequire(import.meta.url));
|
|
16
|
+
//*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A JSON object
|
|
20
|
+
* @typedef { object } JSON
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// TODO: make this live in streams
|
|
24
|
+
|
|
25
|
+
let InternalBuffer = null;
|
|
26
|
+
if (_browserOrNode.isBrowser || _browserOrNode.isJsDom) {
|
|
27
|
+
InternalBuffer = function () {};
|
|
28
|
+
var enc = new TextEncoder();
|
|
29
|
+
var dec = new TextDecoder('utf-8');
|
|
30
|
+
InternalBuffer.from = ob => {
|
|
31
|
+
const type = Array.isArray(ob) ? 'array' : typeof ob;
|
|
32
|
+
switch (type) {
|
|
33
|
+
case 'object':
|
|
34
|
+
case 'array':
|
|
35
|
+
case 'string':
|
|
36
|
+
return enc.encode(ob).buffer;
|
|
37
|
+
case '':
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
InternalBuffer.to = (type, buffer) => {
|
|
41
|
+
switch (type) {
|
|
42
|
+
case 'object':
|
|
43
|
+
case 'array':
|
|
44
|
+
case 'string':
|
|
45
|
+
return dec.decode(buffer);
|
|
46
|
+
case '':
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
InternalBuffer.alloc = (size, fill, encoding = 'utf-8') => {
|
|
50
|
+
const result = new Uint8Array(size);
|
|
51
|
+
if (fill) {
|
|
52
|
+
for (let lcv = 0; lcv < size; lcv++) {
|
|
53
|
+
result[lcv] = fill;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//todo: convert encoding to byte offset
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
InternalBuffer = function () {};
|
|
60
|
+
InternalBuffer.from = (ob = '') => {
|
|
61
|
+
return Buffer.from(ob);
|
|
62
|
+
};
|
|
63
|
+
//InternalBuffer = Buffer;
|
|
64
|
+
InternalBuffer.to = (type, buffer) => {
|
|
65
|
+
switch (type) {
|
|
66
|
+
case 'object':
|
|
67
|
+
return buffer.toJSON();
|
|
68
|
+
case 'array':
|
|
69
|
+
return buffer.toJSON();
|
|
70
|
+
case 'string':
|
|
71
|
+
return buffer.toString();
|
|
72
|
+
case '':
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const FileBuffer = InternalBuffer;
|
|
77
|
+
exports.FileBuffer = FileBuffer;
|