{"_id":"@adamcikado/flydrive","_rev":"1-41d279f19499603c09a7f8943780398f","name":"@adamcikado/flydrive","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.3":{"name":"@adamcikado/flydrive","version":"1.0.3","description":"Flexible and Fluent way to manage storage in Node.js.","homepage":"https://github.com/Slynova-Org/flydrive#readme","license":"MIT","main":"build/index.js","types":"build/index.d.ts","keywords":["storage","filesystem","file","aws","s3","promise","async","spaces","google","cloud"],"author":{"name":"Romain Lanz","email":"romain.lanz@slynova.ch"},"contributors":[{"name":"Harminder Virk","email":"virk@adonisjs.com"},{"name":"Michaël Zasso","email":"targos@pm.me"}],"scripts":{"prepare":"tsc -b tsconfig.json"},"dependencies":{"fs-extra":"^9.0.0","node-exceptions":"^4.0.1"},"devDependencies":{"@types/fs-extra":"^9.0.1"},"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/Slynova-Org/flydrive.git"},"bugs":{"url":"https://github.com/Slynova-Org/flydrive/issues"},"_id":"@adamcikado/flydrive@1.0.3","_nodeVersion":"12.13.1","_npmVersion":"6.12.1","dist":{"integrity":"sha512-OC0rihZ9ZvPhkxgPMoiYYgyashfUJqblq/221tzA1U3Qh2LG4i6fd9fRWzYVxWS+zeWHdBjj6x8rGmPZlnZGsQ==","shasum":"f1c3349e4ca070b0dae10dece26bad15a2342bcb","tarball":"https://registry.npmjs.org/@adamcikado/flydrive/-/flydrive-1.0.3.tgz","fileCount":67,"unpackedSize":71861,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfa2FdCRA9TVsSAnZWagAAqYQP/itZJvMLf98+4d7j450u\n44mcrWmTFM6ZNAJI1mI0fb3ZlmoL+DEudWczshSG5gH4rMfpRPT9nqStf9Hu\nnsKlUMqxuBZljM9Kzmb2hkLDA0dzOZT6lLS7NY/d3mVXQ6Q8thUUMogdVXfd\nixkdLa6COz5mcow57Ybm03mf5os5OJ7iLgzBv4RjdFgp2zpbY8ZeearGd2Wk\nX7112btQqOP1w6ouhItu+gFSAVQkBsxxoWOSjzBTFOU7iz7Wzwgx77JIYP9N\nWAhsDQF2w1XQyhIT7gu4h97qqvwdadldhd0gSYhHwyiqweOulLvnXDMMt/+U\ne/hLWCkG1VJw881f25mmuZQdbIiCc2QeExwvB+rUWm4aIADQeY8Cl5KkAczq\n0P6LVqCjI8g5I6yOytNq2mu7CDVjK/hguyJ+hXU1edQGNIxQhwlwSwc8QRw2\nIf+1uqvp9vsINiflD6GRW59L+B64iqAbaCsATT45mGXWpzFX1J0HpcQkMMFw\n3f+lC6Vwk1qK4lT34l2vsJwkK8U3bMYYiqvgRXYTVQ2YxhGmq4ITj4oha2SQ\n2z4UVP6rzl95MsR8Z8yYmgw3Rn1ZGBHTVAosi3LlY+MmNmzqckdTXE9AvpdM\nTkwYuxzuwPnz/8JPfJ2R5Kl6XQtJp2xodONZlPkv4jvxuXBZtEq6vQ70P4JS\nGHFC\r\n=Qoe7\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCyhtImHyibf8OySVv+aksQMCiibLNfZjChj6tL7cpD5AIgUNgMhYEZr0fIdM+XjHsxxRnqEeqEezG8yeDJZdyhsPo="}]},"maintainers":[{"name":"adamcikado","email":"adamcikado@gmail.com"}],"_npmUser":{"name":"adamcikado","email":"adamcikado@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/flydrive_1.0.3_1600872797096_0.44026831044532244"},"_hasShrinkwrap":false}},"time":{"created":"2020-09-23T14:53:17.040Z","1.0.3":"2020-09-23T14:53:17.195Z","modified":"2022-04-04T11:25:08.828Z"},"maintainers":[{"name":"adamcikado","email":"adamcikado@gmail.com"}],"description":"Flexible and Fluent way to manage storage in Node.js.","homepage":"https://github.com/Slynova-Org/flydrive#readme","keywords":["storage","filesystem","file","aws","s3","promise","async","spaces","google","cloud"],"repository":{"type":"git","url":"git+https://github.com/Slynova-Org/flydrive.git"},"contributors":[{"name":"Harminder Virk","email":"virk@adonisjs.com"},{"name":"Michaël Zasso","email":"targos@pm.me"}],"author":{"name":"Romain Lanz","email":"romain.lanz@slynova.ch"},"bugs":{"url":"https://github.com/Slynova-Org/flydrive/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <img src=\"https://user-images.githubusercontent.com/2793951/54391096-418f4500-46a4-11e9-8d0c-b00ff7ba4198.png\" alt=\"flydrive\">\n</p>\n\n<p align=\"center\">\n  <a href=\"https://www.npmjs.com/package/@slynova/flydrive\"><img src=\"https://img.shields.io/npm/dm/@slynova/flydrive.svg?style=flat-square\" alt=\"Download\"></a>\n  <a href=\"https://www.npmjs.com/package/@slynova/flydrive\"><img src=\"https://img.shields.io/npm/v/@slynova/flydrive.svg?style=flat-square\" alt=\"Version\"></a>\n  <a href=\"https://opensource.org/licenses/MIT\"><img src=\"https://img.shields.io/npm/l/@slynova/flydrive.svg?style=flat-square\" alt=\"License\"></a>\n</p>\n\n`flydrive` is a framework-agnostic package which provides a powerful wrapper to manage file Storage in [Node.js](https://nodejs.org).\n\nThere are currently 3 drivers available:\n\n- `'local'`: Stores files on the local file system.\n- `'s3'`: Amazon S3 and other compatible services\n  - You need to install the `@slynova/flydrive-s3` package to be able to use this driver.\n  - This driver is compatible with DigitalOcean Spaces and Scaleway Object Storage.\n- `'gcs'`: Google Cloud Storage\n  - You need to install the `@slynova/flydrive-gcs` package to be able to use this driver.\n\n---\n\n## Getting Started\n\nThis package is available in the npm registry.\nIt can easily be installed with `npm` or `yarn`.\n\n```bash\n$ npm i @slynova/flydrive\n# or\n$ yarn add @slynova/flydrive\n```\n\nWhen you require the package in your file, it will give you access to the `StorageManager` class.\nThis class is a facade for the package and should be instantiated with a [configuration object](https://github.com/Slynova-Org/flydrive/blob/master/test/stubs/config.ts).\n\n```javascript\nconst { StorageManager } = require('@slynova/flydrive');\nconst storage = new StorageManager(...);\n```\n\nOnce you instantiated the manager, you can use the `StorageManager#disk()` method to retrieve a disk an use it.\n\n```javascript\nstorage.disk(); // Returns the default disk (specified in the config)\nstorage.disk('awsCloud'); // Returns the driver for the disk \"s3\"\nstorage.disk('awsCloud', customConfig); // Overwrite the default configuration of the disk\n```\n\n## Registering External Driver\n\nAfter installing any external driver, like `@slynova/flydrive-gcs`, you need to register it inside our manager to be able to use it.\n\nThe following is done by using the method `storage.registerDriver(name: string, Driver)`.\n\n```ts\nconst { GoogleCloudStorage } = require('@slynova/flydrive-gcs');\nconst { StorageManager } = require('@slynova/flydrive');\nconst storage = new StorageManager(...);\n\nstorage.registerDriver('gcs', GoogleCloudStorage);\n```\n\n## Driver's API\n\nEach driver extends the abstract class [`Storage`](https://github.com/Slynova-Org/flydrive/blob/master/src/Storage.ts). This class will throw an exception for each methods by default. The driver needs to overwrite the methods it supports.\n\nThe following method doesn't exist on the `LocalFileSystemStorage` driver, therefore, it will throw an exception.\n\n```javascript\n// throws \"E_METHOD_NOT_SUPPORTED: Method getSignedUrl is not supported for the driver LocalFileSystemStorage\"\nstorage.disk('local').getSignedUrl();\n```\n\nSince we are using TypeScript, you can make use of casting to get the real interface:\n\n```typescript\nimport { LocalFileSystemStorage } from '@slynova/flydrive';\n\nstorage.disk<LocalFileSystemStorage>('local');\n```\n\n### Response interface\n\nAsynchronous methods will always return a Promise which resolves with a `Response`\nobject. The response object may contain relevant data in its properties (for\nexample, the `ExistsResponse` object for the `exists` method contains a boolean\n`exists` property).\n\nAll responses additionally have a `raw` property which is driver-specific and\ncontains the result from the original call made by the driver.\n\n### Exceptions\n\nIn case of runtime errors, `flydrive` will try to throw driver-agnostic exceptions.\nExceptions also have a `raw` property which contains the original error.\n\n### Methods\n\n<details>\n<summary markdown=\"span\"><code>append(location: string, content: Buffer | Stream | string, options: object): Promise&lt;Response&gt;</code></summary>\n\nThis method will append the content to the file at the location.\nIf the file doesn't exist yet, it will be created.\n\n```javascript\n// Supported drivers: \"local\"\n\nawait storage.disk('local').append('foo.txt', 'bar');\n// foo.txt now has the content `${initialContent}bar`\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>copy(src: string, dest: string, options: object): Promise&lt;Response&gt;</code></summary>\n\nThis method will copy a file to another location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nawait storage.disk('local').copy('foo.txt', 'bar.txt');\n// foo.txt was copied to bar.txt\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>delete(location: string): Promise&lt;DeleteResponse&gt;</code></summary>\n\nThis method will delete the file at the given location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst { wasDeleted } = await storage.disk('local').delete('foo.txt');\n// If a file named foo.txt has been deleted, wasDeleted is true.\n```\n\nThe value returned by this method will have a `wasDeleted` property that\ncan be either a boolean (`true` if a file was deleted, `false` if there was\nno file to delete) or `null` (if no information about the file is available).\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>driver()</code></summary>\n\nThis method returns the driver used if you need to do anything specific not supported by default.\n\n```javascript\nstorage.disk('local').driver(); // Returns the \"fs-extra\" module.\nstorage.disk('awsCloud').driver(); // Returns an instance of the AWS S3 client.\nstorage.disk('googleCloud').driver(); // Returns an instance of the the Google Cloud Storage client.\n// ....\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>exists(location: string): Promise&lt;ExistsResponse&gt;</code></summary>\n\nThis method will determine if a file exists at the given location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst { exists } = await storage.disk('local').exists('foo.txt');\n// exists is true or false\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>get(location: string, encoding: string = 'utf-8'): Promise&lt;ContentResponse&lt;string&gt;&gt;</code></summary>\n\nThis method will return the file's content as a string for the given location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst { content } = await storage.disk('local').get('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>getBuffer(location: string): Promise&lt;ContentResponse&lt;Buffer&gt;&gt;</code></summary>\n\nThis method will return the file's content as a Buffer for the given location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst { content } = await storage.disk('local').exists('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>getSignedUrl(location: string, options: SignedUrlOptions = { expiry: 900 }): Promise&lt;SignedUrlResponse&gt;</code></summary>\n\nThis method will return the signed url for an existing file.\n\n```javascript\n// Supported drivers: \"s3\", \"gcs\"\n\nconst { signedUrl } = await storage.disk('awsCloud').getSignedUrl('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>getStat(location: string): Promise&lt;StatResponse&gt;</code></summary>\n\nThis method will return the file's size (in bytes) and last modification date.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst { size, modified } = await storage.disk('local').getStat('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>getStream(location: string, options: object | string): Stream</code></summary>\n\nThis method will return a Node.js readable stream for the given file.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst stream = storage.disk('local').getStream('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>getUrl(location: string): string</code></summary>\n\nThis method will return a public URL for a given file.\n\n```javascript\n// Supported drivers: \"s3\", \"gcs\"\n\nconst uri = storage.disk('awsCloud').getUrl('foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>move(src: string, dest: string): Promise&lt;Response&gt;</code></summary>\n\nThis method will move the file to a new location.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nawait storage.disk('local').move('foo.txt', 'newFolder/foo.txt');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>put(location: string, content: Buffer | Stream | string, options: object): Promise&lt;Response&gt;</code></summary>\n\nThis method will create a new file with the provided content.\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nawait storage.disk('local').put('bar.txt', 'Foobar');\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>prepend(location: string, content: Buffer | string, options: object): Promise&lt;Response&gt;</code></summary>\n\nThis method will prepend content to a file.\n\n```javascript\n// Supported drivers: \"local\"\n\nawait storage.disk('local').prepend('foo.txt', 'bar');\n// foo.txt now has the content `bar${initialContent}`\n```\n\n</details>\n\n<details>\n<summary markdown=\"span\"><code>flatList(prefix?: string): AsyncIterable&lt;FileListResponse&gt;</code></summary>\n\nThis method will return an async iterator over all file names that start with `prefix` (recursive).\n\n```javascript\n// Supported drivers: \"local\", \"s3\", \"gcs\"\n\nconst disk = storage.disk('local');\nfor await (const filename of disk.flatList('a/b')) {\n  console.log(filename);\n}\n```\n\n</details>\n\n## Contribution Guidelines\n\nAny pull requests or discussions are welcome.\nNote that every pull request providing new feature or correcting a bug should be created with appropriate unit tests.\n","readmeFilename":"README.md"}