@qbraid-core/storage 0.7.0
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 +71 -0
- package/dist/src/client.d.ts +7 -0
- package/dist/src/client.js +42 -0
- package/dist/src/client.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +11 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/types.d.ts +11 -0
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<img align="right" width="100" alt="qbraid" src="https://qbraid-static.s3.amazonaws.com/logos/qbraid.png">
|
|
2
|
+
|
|
3
|
+
# [@qbraid-core/storage](https://qbraid.github.io/qbraid-core-js/modules/_qbraid-core_storage.html)
|
|
4
|
+
|
|
5
|
+
[![Stable][preview-stability]](https://qbraid.github.io/qbraid-core-js/#launch-stages)
|
|
6
|
+
[](https://npm.im/@qbraid-core/storage)
|
|
7
|
+
|
|
8
|
+
Client for the qBraid Quantum storage service.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @qbraid-core/storage
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage Example
|
|
17
|
+
|
|
18
|
+
### Upload a File
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { FileStorageClient } from '@qbraid-core/storage';
|
|
22
|
+
|
|
23
|
+
const client = new FileStorageClient();
|
|
24
|
+
|
|
25
|
+
const filePath = 'path/to/file.txt'; // existing file on the local filesystem
|
|
26
|
+
const namespace = 'my-namespace';
|
|
27
|
+
const objectPath = 'server/path/to/file.txt';
|
|
28
|
+
const response = await client.uploadFile(filePath, namespace, objectPath);
|
|
29
|
+
|
|
30
|
+
console.log(response);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Download a File
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { FileStorageClient } from '@qbraid-core/storage';
|
|
37
|
+
|
|
38
|
+
const client = new FileStorageClient();
|
|
39
|
+
|
|
40
|
+
const namespace = 'my-namespace';
|
|
41
|
+
const objectPath = 'server/path/to/file.txt';
|
|
42
|
+
|
|
43
|
+
const downloadResponse = await client.downloadFile(namespace, objectPath);
|
|
44
|
+
|
|
45
|
+
if (downloadResponse.stream) {
|
|
46
|
+
const stream = downloadResponse.stream as Readable;
|
|
47
|
+
let fileContents = '';
|
|
48
|
+
|
|
49
|
+
stream.on('data', chunk => {
|
|
50
|
+
fileContents += chunk;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
stream.on('end', () => {
|
|
54
|
+
console.log('File contents:', fileContents);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
stream.on('error', err => {
|
|
58
|
+
console.error('Error reading file stream:', err);
|
|
59
|
+
});
|
|
60
|
+
} else if (downloadResponse.error) {
|
|
61
|
+
console.error('Error downloading file:', downloadResponse.error);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
This software is proprietary and subject to the terms of the [qBraid Commercial Software License](https://qbraid.github.io/qbraid-core-js/#license).
|
|
68
|
+
|
|
69
|
+
[stable-stability]: https://img.shields.io/badge/stability-stable-green
|
|
70
|
+
[preview-stability]: https://img.shields.io/badge/stability-preview-orange
|
|
71
|
+
[deprecated-stability]: https://img.shields.io/badge/stability-deprecated-red
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QbraidSession, QbraidClient } from '@qbraid-core/base';
|
|
2
|
+
import { DownloadFileResponse, UploadFileResponse } from './types';
|
|
3
|
+
export declare class FileStorageClient extends QbraidClient {
|
|
4
|
+
constructor(session?: QbraidSession);
|
|
5
|
+
downloadFile(namespace: string, objectPath: string): Promise<DownloadFileResponse>;
|
|
6
|
+
uploadFile(filePath: string, namespace: string, objectPath: string, overwrite?: boolean): Promise<UploadFileResponse>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.FileStorageClient = void 0;
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const stream_1 = require("stream");
|
|
11
|
+
const base_1 = require("@qbraid-core/base");
|
|
12
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
13
|
+
class FileStorageClient extends base_1.QbraidClient {
|
|
14
|
+
constructor(session) {
|
|
15
|
+
super(session);
|
|
16
|
+
}
|
|
17
|
+
async downloadFile(namespace, objectPath) {
|
|
18
|
+
const response = await this.session.client.get(`/files/download/${namespace}/${objectPath}`, { responseType: 'stream' });
|
|
19
|
+
// the response can either be a stream
|
|
20
|
+
if (response.data instanceof stream_1.Readable) {
|
|
21
|
+
return { stream: response.data };
|
|
22
|
+
}
|
|
23
|
+
// or an error message
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
async uploadFile(filePath, namespace, objectPath, overwrite = false) {
|
|
27
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
28
|
+
throw new Error(`File at path ${filePath} does not exist`);
|
|
29
|
+
}
|
|
30
|
+
const form = new form_data_1.default();
|
|
31
|
+
form.append('file', (0, fs_1.createReadStream)(filePath));
|
|
32
|
+
form.append('namespace', namespace);
|
|
33
|
+
form.append('objectPath', objectPath);
|
|
34
|
+
form.append('overwrite', overwrite.toString());
|
|
35
|
+
const response = await this.session.client.post('/files/upload', form, {
|
|
36
|
+
headers: form.getHeaders(),
|
|
37
|
+
});
|
|
38
|
+
return response.data;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.FileStorageClient =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C,CAAC;QACtC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAqB,eAAe,EAAE,IAAI,EAAE;YACzF,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;SAC3B,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AA1CD,8CA0CC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2025, qBraid Development Team
|
|
3
|
+
// All rights reserved.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.FileStorageClient = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* @module storage
|
|
8
|
+
*/
|
|
9
|
+
var client_1 = require("./client");
|
|
10
|
+
Object.defineProperty(exports, "FileStorageClient", { enumerable: true, get: function () { return client_1.FileStorageClient; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB;;;AAEvB;;GAEG;AAEH,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,uBAAuB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qbraid-core/storage",
|
|
3
|
+
"description": "Client for the qBraid file storage service.",
|
|
4
|
+
"version": "0.7.0",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"author": "qBraid Development Team",
|
|
8
|
+
"license": "Proprietary",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/src"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"qbraid",
|
|
14
|
+
"qbraid-core",
|
|
15
|
+
"qbraid-core-js",
|
|
16
|
+
"qbraid storage",
|
|
17
|
+
"qbraid cloud",
|
|
18
|
+
"qbraid api",
|
|
19
|
+
"qbraid apis",
|
|
20
|
+
"cloud",
|
|
21
|
+
"quantum",
|
|
22
|
+
"quantum computing"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"directory": "packages/storage",
|
|
27
|
+
"url": "git+https://github.com/qBraid/qbraid-core-js.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://qbraid.github.io/qbraid-core-js/modules/storage.html",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@qbraid-core/base": "0.7.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"clean": "rimraf dist tsconfig.tsbuildinfo src/*.d.ts src/*.js",
|
|
35
|
+
"lint": "eslint src",
|
|
36
|
+
"lint:fix": "eslint src --fix",
|
|
37
|
+
"format": "prettier --write \"src/**/*.{ts,json}\"",
|
|
38
|
+
"format:check": "prettier --check \"src/**/*.{ts,json}\"",
|
|
39
|
+
"docs": "typedoc"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
}
|
|
44
|
+
}
|