@twin.org/blob-storage-connector-azure 0.0.1-next.16 → 0.0.1-next.17
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/dist/cjs/index.cjs +3 -24
- package/dist/esm/index.mjs +3 -24
- package/docs/changelog.md +1 -1
- package/package.json +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var node_stream = require('node:stream');
|
|
4
3
|
var storageBlob = require('@azure/storage-blob');
|
|
5
4
|
var core = require('@twin.org/core');
|
|
6
5
|
var crypto = require('@twin.org/crypto');
|
|
@@ -114,18 +113,7 @@ class AzureBlobStorageConnector {
|
|
|
114
113
|
try {
|
|
115
114
|
const id = core.Converter.bytesToHex(crypto.Sha256.sum256(blob));
|
|
116
115
|
const blockBlobClient = this._azureContainerClient.getBlockBlobClient(id);
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Reads data from the blob and pushes it into the stream.
|
|
120
|
-
* This method is automatically called when the stream is read from.
|
|
121
|
-
* It pushes the blob data and signals the end of the stream.
|
|
122
|
-
*/
|
|
123
|
-
read() {
|
|
124
|
-
this.push(blob);
|
|
125
|
-
this.push(null);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
await blockBlobClient.uploadStream(readableStream);
|
|
116
|
+
await blockBlobClient.uploadData(blob);
|
|
129
117
|
return `blob:${new core.Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;
|
|
130
118
|
}
|
|
131
119
|
catch (err) {
|
|
@@ -149,17 +137,8 @@ class AzureBlobStorageConnector {
|
|
|
149
137
|
try {
|
|
150
138
|
const key = urnParsed.namespaceSpecific(1);
|
|
151
139
|
const blobClient = this._azureContainerClient.getBlobClient(key);
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const readableStream = downloadResponse.readableStreamBody;
|
|
155
|
-
const chunks = [];
|
|
156
|
-
for await (const chunk of readableStream) {
|
|
157
|
-
chunks.push(chunk);
|
|
158
|
-
}
|
|
159
|
-
const buffer = Buffer.concat(chunks);
|
|
160
|
-
return new Uint8Array(buffer);
|
|
161
|
-
}
|
|
162
|
-
return undefined;
|
|
140
|
+
const buffer = await blobClient.downloadToBuffer();
|
|
141
|
+
return new Uint8Array(buffer);
|
|
163
142
|
}
|
|
164
143
|
catch (err) {
|
|
165
144
|
throw new core.GeneralError(this.CLASS_NAME, "getBlobFailed", {
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Readable } from 'node:stream';
|
|
2
1
|
import { BlobServiceClient, StorageSharedKeyCredential } from '@azure/storage-blob';
|
|
3
2
|
import { Guards, BaseError, Converter, Urn, GeneralError } from '@twin.org/core';
|
|
4
3
|
import { Sha256 } from '@twin.org/crypto';
|
|
@@ -112,18 +111,7 @@ class AzureBlobStorageConnector {
|
|
|
112
111
|
try {
|
|
113
112
|
const id = Converter.bytesToHex(Sha256.sum256(blob));
|
|
114
113
|
const blockBlobClient = this._azureContainerClient.getBlockBlobClient(id);
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Reads data from the blob and pushes it into the stream.
|
|
118
|
-
* This method is automatically called when the stream is read from.
|
|
119
|
-
* It pushes the blob data and signals the end of the stream.
|
|
120
|
-
*/
|
|
121
|
-
read() {
|
|
122
|
-
this.push(blob);
|
|
123
|
-
this.push(null);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
await blockBlobClient.uploadStream(readableStream);
|
|
114
|
+
await blockBlobClient.uploadData(blob);
|
|
127
115
|
return `blob:${new Urn(AzureBlobStorageConnector.NAMESPACE, id).toString()}`;
|
|
128
116
|
}
|
|
129
117
|
catch (err) {
|
|
@@ -147,17 +135,8 @@ class AzureBlobStorageConnector {
|
|
|
147
135
|
try {
|
|
148
136
|
const key = urnParsed.namespaceSpecific(1);
|
|
149
137
|
const blobClient = this._azureContainerClient.getBlobClient(key);
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
const readableStream = downloadResponse.readableStreamBody;
|
|
153
|
-
const chunks = [];
|
|
154
|
-
for await (const chunk of readableStream) {
|
|
155
|
-
chunks.push(chunk);
|
|
156
|
-
}
|
|
157
|
-
const buffer = Buffer.concat(chunks);
|
|
158
|
-
return new Uint8Array(buffer);
|
|
159
|
-
}
|
|
160
|
-
return undefined;
|
|
138
|
+
const buffer = await blobClient.downloadToBuffer();
|
|
139
|
+
return new Uint8Array(buffer);
|
|
161
140
|
}
|
|
162
141
|
catch (err) {
|
|
163
142
|
throw new GeneralError(this.CLASS_NAME, "getBlobFailed", {
|
package/docs/changelog.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/blob-storage-connector-azure",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.17",
|
|
4
4
|
"description": "Blob Storage connector implementation using Azure",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@azure/storage-blob": "^12.
|
|
18
|
-
"@twin.org/blob-storage-models": "0.0.1-next.
|
|
17
|
+
"@azure/storage-blob": "^12.26.0",
|
|
18
|
+
"@twin.org/blob-storage-models": "0.0.1-next.17",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/crypto": "next",
|
|
21
21
|
"@twin.org/logging-models": "next",
|