@flystorage/file-storage 0.0.8 → 0.0.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  <img src="https://avatars.githubusercontent.com/u/151840999" width="50px" height="50px" />
2
2
 
3
- # Flystorage
3
+ # Flystorage (work in progress)
4
4
  Flystorage is a file storage abstraction for NodeJS and TypeScript. It is an 80/20 solution
5
5
  that is built around a set of goals:
6
6
 
@@ -41,12 +41,13 @@ to, simply because they cannot be abstracted over in a reasonable manner.
41
41
  ### Implemented
42
42
  - [x] Local Filesystem
43
43
  - [x] AWS S3 (using the V3 SDK)
44
+ - [x] Azure Blob Storage
45
+ - [x] Test implementation (in-memory)
44
46
 
45
47
  ### Planned
46
48
 
47
49
  #### Prio 1
48
- - [ ] Azure Blob Storage
49
- - [ ] Test implementation (in-memory, with staged errors)
50
+ - [ ] Failure decorator (stage errors for tests)
50
51
  - [ ] Google Cloud Storage
51
52
 
52
53
  ### Prio 2
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readableToUint8Array = exports.readableToString = exports.closeReadable = exports.normalizeExpiryToMilliseconds = exports.normalizeExpiryToDate = exports.FileStorage = exports.DirectoryListing = exports.isDirectory = exports.isFile = void 0;
3
+ exports.readableToUint8Array = exports.readableToString = exports.closeReadable = exports.normalizeExpiryToMilliseconds = exports.normalizeExpiryToDate = exports.FileStorage = exports.toReadable = exports.DirectoryListing = exports.isDirectory = exports.isFile = void 0;
4
4
  const stream_1 = require("stream");
5
5
  const checksum_from_stream_js_1 = require("./checksum-from-stream.js");
6
6
  const errors = require("./errors.js");
7
7
  const errors_js_1 = require("./errors.js");
8
8
  const path_normalizer_js_1 = require("./path-normalizer.js");
9
+ const util_1 = require("util");
9
10
  function isFile(stat) {
10
11
  return stat.isFile;
11
12
  }
@@ -59,6 +60,7 @@ function toReadable(contents) {
59
60
  }
60
61
  return stream_1.Readable.from(contents);
61
62
  }
63
+ exports.toReadable = toReadable;
62
64
  const naturalSorting = new Intl.Collator(undefined, {
63
65
  numeric: true,
64
66
  sensitivity: 'base'
@@ -272,13 +274,23 @@ async function closeReadable(body) {
272
274
  exports.closeReadable = closeReadable;
273
275
  const decoder = new TextDecoder();
274
276
  async function readableToString(stream) {
275
- return decoder.decode(await readableToUint8Array(stream));
277
+ const contents = decoder.decode(await readableToUint8Array(stream));
278
+ await closeReadable(stream);
279
+ return contents;
276
280
  }
277
281
  exports.readableToString = readableToString;
282
+ const encoder = new util_1.TextEncoder();
278
283
  function readableToUint8Array(stream) {
279
284
  return new Promise((resolve, reject) => {
280
285
  const parts = [];
281
286
  stream.on('data', (chunk) => {
287
+ const type = typeof chunk;
288
+ if (type === 'string') {
289
+ chunk = encoder.encode(chunk);
290
+ }
291
+ else if (type === 'number') {
292
+ chunk = new Uint8Array([chunk]);
293
+ }
282
294
  parts.push(chunk);
283
295
  });
284
296
  stream.on('error', reject);
@@ -287,7 +299,7 @@ function readableToUint8Array(stream) {
287
299
  }
288
300
  exports.readableToUint8Array = readableToUint8Array;
289
301
  function concatUint8Arrays(input) {
290
- const length = input.reduce((l, a) => l + a.byteLength, 0);
302
+ const length = input.reduce((l, a) => l + (a.byteLength), 0);
291
303
  const output = new Uint8Array(length);
292
304
  let position = 0;
293
305
  input.forEach(i => {
@@ -3,6 +3,7 @@ import { checksumFromStream } from './checksum-from-stream.js';
3
3
  import * as errors from './errors.js';
4
4
  import { ChecksumIsNotAvailable } from './errors.js';
5
5
  import { PathNormalizerV1 } from './path-normalizer.js';
6
+ import { TextEncoder } from "util";
6
7
  export function isFile(stat) {
7
8
  return stat.isFile;
8
9
  }
@@ -47,7 +48,7 @@ export class DirectoryListing {
47
48
  }
48
49
  }
49
50
  }
50
- function toReadable(contents) {
51
+ export function toReadable(contents) {
51
52
  if (contents instanceof Readable) {
52
53
  return contents;
53
54
  }
@@ -262,12 +263,22 @@ export async function closeReadable(body) {
262
263
  }
263
264
  const decoder = new TextDecoder();
264
265
  export async function readableToString(stream) {
265
- return decoder.decode(await readableToUint8Array(stream));
266
+ const contents = decoder.decode(await readableToUint8Array(stream));
267
+ await closeReadable(stream);
268
+ return contents;
266
269
  }
270
+ const encoder = new TextEncoder();
267
271
  export function readableToUint8Array(stream) {
268
272
  return new Promise((resolve, reject) => {
269
273
  const parts = [];
270
274
  stream.on('data', (chunk) => {
275
+ const type = typeof chunk;
276
+ if (type === 'string') {
277
+ chunk = encoder.encode(chunk);
278
+ }
279
+ else if (type === 'number') {
280
+ chunk = new Uint8Array([chunk]);
281
+ }
271
282
  parts.push(chunk);
272
283
  });
273
284
  stream.on('error', reject);
@@ -275,7 +286,7 @@ export function readableToUint8Array(stream) {
275
286
  });
276
287
  }
277
288
  function concatUint8Arrays(input) {
278
- const length = input.reduce((l, a) => l + a.byteLength, 0);
289
+ const length = input.reduce((l, a) => l + (a.byteLength), 0);
279
290
  const output = new Uint8Array(length);
280
291
  let position = 0;
281
292
  input.forEach(i => {
@@ -57,7 +57,7 @@ export declare class DirectoryListing implements AsyncIterable<StatEntry> {
57
57
  filter(filter: (entry: StatEntry) => boolean): DirectoryListing;
58
58
  [Symbol.asyncIterator](): AsyncGenerator<StatEntry, void, unknown>;
59
59
  }
60
- export type FileContents = Iterable<any> | AsyncIterable<any> | NodeJS.ReadableStream | Readable;
60
+ export type FileContents = Iterable<any> | AsyncIterable<any> | NodeJS.ReadableStream | Readable | string;
61
61
  export type MiscellaneousOptions = {
62
62
  [option: string]: any;
63
63
  };
@@ -101,6 +101,7 @@ export type ConfigurationOptions = {
101
101
  checksums?: ChecksumOptions;
102
102
  mimeTypes?: MimeTypeOptions;
103
103
  };
104
+ export declare function toReadable(contents: FileContents): Readable;
104
105
  export declare class FileStorage {
105
106
  private readonly adapter;
106
107
  private readonly pathNormalizer;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@flystorage/file-storage",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "description": "File-storage abstraction: multiple filesystems, one API.",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "types": "./dist/types/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  }
19
19
  },
20
20
  "scripts": {
21
- "compile": "concurrently npm:compile:* && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
21
+ "compile": "rm -rf ./dist/ && concurrently npm:compile:* && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json",
22
22
  "compile:esm": "tsc --outDir ./dist/esm/ --declaration false",
23
23
  "compile:cjs": "tsc --outDir ./dist/cjs/ --declaration false --module commonjs --moduleResolution node",
24
24
  "compile:types": "tsc --outDir ./dist/types/ --declaration --emitDeclarationOnly",
@@ -27,7 +27,7 @@
27
27
  "author": "Frank de Jonge (https://frankdejonge.nl)",
28
28
  "repository": {
29
29
  "type": "git",
30
- "url": "git+https://github.com/flystorage/flystorage.git",
30
+ "url": "git+https://github.com/duna-oss/flystorage.git",
31
31
  "directory": "packages/file-storage"
32
32
  },
33
33
  "keywords": [