@environment-safe/file 0.3.0 → 0.3.2

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/.husky/pre-commit CHANGED
@@ -4,6 +4,7 @@
4
4
  npm run lint
5
5
  npm run path-test
6
6
  npm run headless-browser-path-test
7
+ npm run link-local-moka
7
8
  npm run import-test
8
9
  npm run headless-browser-test
9
10
  #npm run build-commonjs
package/README.md CHANGED
@@ -111,3 +111,5 @@ All work is done in the .mjs files and will be transpiled on commit to commonjs
111
111
 
112
112
  If the above tests pass, then attempt a commit which will generate .d.ts files alongside the `src` files and commonjs classes in `dist`
113
113
 
114
+ In order to run the `import-test`, you must link the local `moka`, which can be done with `npm run link-local-moka` This is normally solved via dependency hoisting except in the case where you are developing on the file API which has a circular dependency with `moka`.
115
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@environment-safe/file",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "src/index.mjs",
@@ -77,7 +77,7 @@
77
77
  "@environment-safe/chai": "^0.1.0",
78
78
  "@environment-safe/commonjs-builder": "^0.0.3",
79
79
  "@environment-safe/jsdoc-builder": "^0.0.2",
80
- "@open-automaton/moka": "^0.5.0",
80
+ "@open-automaton/moka": "^0.5.1",
81
81
  "babel-plugin-search-and-replace": "^1.1.1",
82
82
  "babel-plugin-transform-import-meta": "^2.2.0",
83
83
  "chai": "^4.3.7",
@@ -110,6 +110,7 @@
110
110
  "container-test": "docker build . -t environment-safe-package.json -f ./containers/test.dockerfile; docker logs --follow \"$(docker run -d environment-safe-package.json)\"",
111
111
  "build-docs": "build-jsdoc docs",
112
112
  "build-types": "build-jsdoc types",
113
+ "link-local-moka":"npm link ../../@open-automaton/moka; cd ../../@open-automaton/moka; npm link ../../@environment-safe/file",
113
114
  "add-generated-files-to-commit": "git add docs/*.md; git add src/*.d.ts; git add dist/*.cjs",
114
115
  "prepare": "husky install"
115
116
  },
package/src/buffer.mjs CHANGED
@@ -142,7 +142,17 @@ if(isBrowser || isJsDom){
142
142
  case 'string':
143
143
  return buffer.toString();
144
144
  case 'base64':
145
- return buffer.toString('base64');
145
+ if(buffer.constructor.name === 'ArrayBuffer'){
146
+ return btoa([].reduce.call(
147
+ new Uint8Array(buffer),
148
+ function(p,c){
149
+ return p+String.fromCharCode(c);
150
+ },
151
+ ''
152
+ ));
153
+ }else{
154
+ return buffer.toString('base64');
155
+ }
146
156
  case '':
147
157
 
148
158
  }
@@ -343,7 +343,8 @@ export const serverFile = {
343
343
  const parsed = new Path(path);
344
344
  const url = parsed.toUrl('native');
345
345
  return await new Promise((resolve, reject)=>{
346
- fs.writeFile(url, buffer, (err)=>{
346
+ const outBuffer = (buffer.constructor.name === 'ArrayBuffer')?FileBuffer.from(buffer):buffer;
347
+ fs.writeFile(url, outBuffer, (err)=>{
347
348
  if(err) return reject(err);
348
349
  if(globalThis.handleWrite){
349
350
  globalThis.handleWrite({
@@ -354,7 +355,7 @@ export const serverFile = {
354
355
  return FileBuffer.toString('string', buffer);
355
356
  },
356
357
  arrayBuffer: ()=> buffer,
357
- });
358
+ });
358
359
  }
359
360
  resolve();
360
361
  });
package/src/index.mjs CHANGED
@@ -27,8 +27,14 @@ let remote=null;
27
27
 
28
28
  export const initialized = async (path, options={})=>{
29
29
  if(isServer){
30
- if(serverFile) return;
31
- serverFile = await sf.initialize();
30
+ if(path.indexOf('://') !== -1){
31
+ if(remote) return;
32
+ //remote url
33
+ remote = await r.initialize();
34
+ }else{
35
+ if(serverFile) return;
36
+ serverFile = await sf.initialize();
37
+ }
32
38
  }else{
33
39
  if(isLocalFileRoot){
34
40
  if(file) return;
@@ -70,7 +76,11 @@ export const act = async (action, ...args)=>{
70
76
  const options = args[1] || {};
71
77
  await initialized(path, options);
72
78
  if(isServer){
73
- return serverFile[action].apply(serverFile, args);
79
+ if(path.indexOf('://') !== -1){
80
+ return remote[action].apply(remote, args);
81
+ }else{
82
+ return serverFile[action].apply(serverFile, args);
83
+ }
74
84
  }else{
75
85
  if(isLocalFileRoot){
76
86
  return file[action].apply(file, args);