@salesforce/lds-store-binary 1.302.0 → 1.304.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/dist/BinaryStore.d.ts
CHANGED
|
@@ -121,4 +121,32 @@ export interface BinaryStore {
|
|
|
121
121
|
* as opaque).
|
|
122
122
|
*/
|
|
123
123
|
setCanonicalUrl(uri: string, canonicalUrl: string, ttlSeconds: number): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a stream that can be used to write buffered chunks of base64-encoded data.
|
|
126
|
+
* This function should be used in conjunction with writeToStream() and closeStream().
|
|
127
|
+
*
|
|
128
|
+
* @param type The MIME type of the binary file. Ex: "image/png".
|
|
129
|
+
* @returns A Promise of a string representing the URI of the binary file. NOTE: the URI
|
|
130
|
+
* to a binary file should be treated as opaque (only use it to pass into methods
|
|
131
|
+
* on this interface).
|
|
132
|
+
*/
|
|
133
|
+
createStream(type: string): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Writes a base64-encoded chunk of data to the stream identified by the stream uri provided
|
|
136
|
+
* by the call from createStream().
|
|
137
|
+
*
|
|
138
|
+
* @param uri The URI of the file.
|
|
139
|
+
* @returns A Promise of a string representing the URI of the binary file that was succesfully
|
|
140
|
+
* written to.
|
|
141
|
+
*/
|
|
142
|
+
writeToStream(uri: string, chunk: string): Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Closes the stream represented by the given uri. Once a stream is closed, it cannot be
|
|
145
|
+
* written to and will cause an error to be returned.
|
|
146
|
+
*
|
|
147
|
+
* @param uri The URI of the file.
|
|
148
|
+
* @returns A Promise of a string representing the URI of the binary file that was succesfully
|
|
149
|
+
* closed.
|
|
150
|
+
*/
|
|
151
|
+
closeStream(uri: string): Promise<string>;
|
|
124
152
|
}
|
|
@@ -7,6 +7,8 @@ export declare class InMemoryBinaryStore implements BinaryStore {
|
|
|
7
7
|
private readonly networkAdapter;
|
|
8
8
|
private counter;
|
|
9
9
|
private fileInfoMap;
|
|
10
|
+
private streamsInProgress;
|
|
11
|
+
private streamTypes;
|
|
10
12
|
private buildUniqueUri;
|
|
11
13
|
constructor(networkAdapter: (uri: string) => Promise<{
|
|
12
14
|
data: Uint8Array;
|
|
@@ -17,4 +19,7 @@ export declare class InMemoryBinaryStore implements BinaryStore {
|
|
|
17
19
|
get(uri: string, options?: GetOptions): Promise<Uint8Array | null>;
|
|
18
20
|
delete(uri: string): Promise<void>;
|
|
19
21
|
setCanonicalUrl(uri: string, canonicalUrl: string, ttlSeconds: number): Promise<string>;
|
|
22
|
+
createStream(type: string): Promise<string>;
|
|
23
|
+
writeToStream(uri: string, chunk: string): Promise<string>;
|
|
24
|
+
closeStream(uri: string): Promise<string>;
|
|
20
25
|
}
|
|
@@ -12,6 +12,8 @@ export class InMemoryBinaryStore {
|
|
|
12
12
|
this.networkAdapter = networkAdapter;
|
|
13
13
|
this.counter = 0;
|
|
14
14
|
this.fileInfoMap = new Map();
|
|
15
|
+
this.streamsInProgress = new Map();
|
|
16
|
+
this.streamTypes = new Map();
|
|
15
17
|
}
|
|
16
18
|
async store(data, type, size) {
|
|
17
19
|
const uri = this.buildUniqueUri();
|
|
@@ -110,5 +112,35 @@ export class InMemoryBinaryStore {
|
|
|
110
112
|
});
|
|
111
113
|
return uri;
|
|
112
114
|
}
|
|
115
|
+
async createStream(type) {
|
|
116
|
+
const uri = this.buildUniqueUri();
|
|
117
|
+
this.streamsInProgress.set(uri, new Uint8Array());
|
|
118
|
+
this.streamTypes.set(uri, type);
|
|
119
|
+
return Promise.resolve(uri);
|
|
120
|
+
}
|
|
121
|
+
async writeToStream(uri, chunk) {
|
|
122
|
+
const existingBytes = this.streamsInProgress.get(uri);
|
|
123
|
+
const newBytes = Buffer.from(chunk, 'base64');
|
|
124
|
+
let combinedBytes = new Uint8Array([...existingBytes, ...newBytes]);
|
|
125
|
+
this.streamsInProgress.set(uri, combinedBytes);
|
|
126
|
+
return Promise.resolve(uri);
|
|
127
|
+
}
|
|
128
|
+
async closeStream(uri) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const data = (_a = this.streamsInProgress.get(uri)) !== null && _a !== void 0 ? _a : new Uint8Array();
|
|
131
|
+
const type = (_b = this.streamTypes.get(uri)) !== null && _b !== void 0 ? _b : 'undefined';
|
|
132
|
+
this.streamsInProgress.delete(uri);
|
|
133
|
+
this.streamTypes.delete(uri);
|
|
134
|
+
// also add it to the store for testing
|
|
135
|
+
this.fileInfoMap.set(uri, {
|
|
136
|
+
data: data,
|
|
137
|
+
type: type,
|
|
138
|
+
size: data.length,
|
|
139
|
+
canonicalUrl: null,
|
|
140
|
+
ttlSeconds: null,
|
|
141
|
+
expiration: null,
|
|
142
|
+
});
|
|
143
|
+
return Promise.resolve(uri);
|
|
144
|
+
}
|
|
113
145
|
}
|
|
114
146
|
//# sourceMappingURL=InMemoryBinaryStore.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InMemoryBinaryStore.js","sourceRoot":"","sources":["../src/InMemoryBinaryStore.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,OAAO,mBAAmB;
|
|
1
|
+
{"version":3,"file":"InMemoryBinaryStore.js","sourceRoot":"","sources":["../src/InMemoryBinaryStore.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAM5B,qEAAqE;IACrE,uDAAuD;IAC/C,cAAc;QAClB,OAAO,yBAAyB,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;IACrD,CAAC;IAED,YACqB,cAE+B;QAF/B,mBAAc,GAAd,cAAc,CAEiB;QAd5C,YAAO,GAAG,CAAC,CAAC;QACZ,gBAAW,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC1C,sBAAiB,GAAG,IAAI,GAAG,EAAsB,CAAC;QAClD,gBAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAY7C,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,IAAgB,EAAE,IAAY,EAA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