1 | // Copyright (c) Microsoft Corporation.
|
2 | // Licensed under the MIT license.
|
3 | import { isNode } from "@azure/core-http";
|
4 | import { RetriableReadableStream, } from "./utils/RetriableReadableStream";
|
5 | /**
|
6 | * ONLY AVAILABLE IN NODE.JS RUNTIME.
|
7 | *
|
8 | * BlobDownloadResponse implements BlobDownloadResponseParsed interface, and in Node.js runtime it will
|
9 | * automatically retry when internal read stream unexpected ends. (This kind of unexpected ends cannot
|
10 | * trigger retries defined in pipeline retry policy.)
|
11 | *
|
12 | * The {@link readableStreamBody} stream will retry underlayer, you can just use it as a normal Node.js
|
13 | * Readable stream.
|
14 | */
|
15 | export class BlobDownloadResponse {
|
16 | /**
|
17 | * Creates an instance of BlobDownloadResponse.
|
18 | *
|
19 | * @param originalResponse -
|
20 | * @param getter -
|
21 | * @param offset -
|
22 | * @param count -
|
23 | * @param options -
|
24 | */
|
25 | constructor(originalResponse, getter, offset, count, options = {}) {
|
26 | this.originalResponse = originalResponse;
|
27 | this.blobDownloadStream = new RetriableReadableStream(this.originalResponse.readableStreamBody, getter, offset, count, options);
|
28 | }
|
29 | /**
|
30 | * Indicates that the service supports
|
31 | * requests for partial file content.
|
32 | *
|
33 | * @readonly
|
34 | */
|
35 | get acceptRanges() {
|
36 | return this.originalResponse.acceptRanges;
|
37 | }
|
38 | /**
|
39 | * Returns if it was previously specified
|
40 | * for the file.
|
41 | *
|
42 | * @readonly
|
43 | */
|
44 | get cacheControl() {
|
45 | return this.originalResponse.cacheControl;
|
46 | }
|
47 | /**
|
48 | * Returns the value that was specified
|
49 | * for the 'x-ms-content-disposition' header and specifies how to process the
|
50 | * response.
|
51 | *
|
52 | * @readonly
|
53 | */
|
54 | get contentDisposition() {
|
55 | return this.originalResponse.contentDisposition;
|
56 | }
|
57 | /**
|
58 | * Returns the value that was specified
|
59 | * for the Content-Encoding request header.
|
60 | *
|
61 | * @readonly
|
62 | */
|
63 | get contentEncoding() {
|
64 | return this.originalResponse.contentEncoding;
|
65 | }
|
66 | /**
|
67 | * Returns the value that was specified
|
68 | * for the Content-Language request header.
|
69 | *
|
70 | * @readonly
|
71 | */
|
72 | get contentLanguage() {
|
73 | return this.originalResponse.contentLanguage;
|
74 | }
|
75 | /**
|
76 | * The current sequence number for a
|
77 | * page blob. This header is not returned for block blobs or append blobs.
|
78 | *
|
79 | * @readonly
|
80 | */
|
81 | get blobSequenceNumber() {
|
82 | return this.originalResponse.blobSequenceNumber;
|
83 | }
|
84 | /**
|
85 | * The blob's type. Possible values include:
|
86 | * 'BlockBlob', 'PageBlob', 'AppendBlob'.
|
87 | *
|
88 | * @readonly
|
89 | */
|
90 | get blobType() {
|
91 | return this.originalResponse.blobType;
|
92 | }
|
93 | /**
|
94 | * The number of bytes present in the
|
95 | * response body.
|
96 | *
|
97 | * @readonly
|
98 | */
|
99 | get contentLength() {
|
100 | return this.originalResponse.contentLength;
|
101 | }
|
102 | /**
|
103 | * If the file has an MD5 hash and the
|
104 | * request is to read the full file, this response header is returned so that
|
105 | * the client can check for message content integrity. If the request is to
|
106 | * read a specified range and the 'x-ms-range-get-content-md5' is set to
|
107 | * true, then the request returns an MD5 hash for the range, as long as the
|
108 | * range size is less than or equal to 4 MB. If neither of these sets of
|
109 | * conditions is true, then no value is returned for the 'Content-MD5'
|
110 | * header.
|
111 | *
|
112 | * @readonly
|
113 | */
|
114 | get contentMD5() {
|
115 | return this.originalResponse.contentMD5;
|
116 | }
|
117 | /**
|
118 | * Indicates the range of bytes returned if
|
119 | * the client requested a subset of the file by setting the Range request
|
120 | * header.
|
121 | *
|
122 | * @readonly
|
123 | */
|
124 | get contentRange() {
|
125 | return this.originalResponse.contentRange;
|
126 | }
|
127 | /**
|
128 | * The content type specified for the file.
|
129 | * The default content type is 'application/octet-stream'
|
130 | *
|
131 | * @readonly
|
132 | */
|
133 | get contentType() {
|
134 | return this.originalResponse.contentType;
|
135 | }
|
136 | /**
|
137 | * Conclusion time of the last attempted
|
138 | * Copy File operation where this file was the destination file. This value
|
139 | * can specify the time of a completed, aborted, or failed copy attempt.
|
140 | *
|
141 | * @readonly
|
142 | */
|
143 | get copyCompletedOn() {
|
144 | return this.originalResponse.copyCompletedOn;
|
145 | }
|
146 | /**
|
147 | * String identifier for the last attempted Copy
|
148 | * File operation where this file was the destination file.
|
149 | *
|
150 | * @readonly
|
151 | */
|
152 | get copyId() {
|
153 | return this.originalResponse.copyId;
|
154 | }
|
155 | /**
|
156 | * Contains the number of bytes copied and
|
157 | * the total bytes in the source in the last attempted Copy File operation
|
158 | * where this file was the destination file. Can show between 0 and
|
159 | * Content-Length bytes copied.
|
160 | *
|
161 | * @readonly
|
162 | */
|
163 | get copyProgress() {
|
164 | return this.originalResponse.copyProgress;
|
165 | }
|
166 | /**
|
167 | * URL up to 2KB in length that specifies the
|
168 | * source file used in the last attempted Copy File operation where this file
|
169 | * was the destination file.
|
170 | *
|
171 | * @readonly
|
172 | */
|
173 | get copySource() {
|
174 | return this.originalResponse.copySource;
|
175 | }
|
176 | /**
|
177 | * State of the copy operation
|
178 | * identified by 'x-ms-copy-id'. Possible values include: 'pending',
|
179 | * 'success', 'aborted', 'failed'
|
180 | *
|
181 | * @readonly
|
182 | */
|
183 | get copyStatus() {
|
184 | return this.originalResponse.copyStatus;
|
185 | }
|
186 | /**
|
187 | * Only appears when
|
188 | * x-ms-copy-status is failed or pending. Describes cause of fatal or
|
189 | * non-fatal copy operation failure.
|
190 | *
|
191 | * @readonly
|
192 | */
|
193 | get copyStatusDescription() {
|
194 | return this.originalResponse.copyStatusDescription;
|
195 | }
|
196 | /**
|
197 | * When a blob is leased,
|
198 | * specifies whether the lease is of infinite or fixed duration. Possible
|
199 | * values include: 'infinite', 'fixed'.
|
200 | *
|
201 | * @readonly
|
202 | */
|
203 | get leaseDuration() {
|
204 | return this.originalResponse.leaseDuration;
|
205 | }
|
206 | /**
|
207 | * Lease state of the blob. Possible
|
208 | * values include: 'available', 'leased', 'expired', 'breaking', 'broken'.
|
209 | *
|
210 | * @readonly
|
211 | */
|
212 | get leaseState() {
|
213 | return this.originalResponse.leaseState;
|
214 | }
|
215 | /**
|
216 | * The current lease status of the
|
217 | * blob. Possible values include: 'locked', 'unlocked'.
|
218 | *
|
219 | * @readonly
|
220 | */
|
221 | get leaseStatus() {
|
222 | return this.originalResponse.leaseStatus;
|
223 | }
|
224 | /**
|
225 | * A UTC date/time value generated by the service that
|
226 | * indicates the time at which the response was initiated.
|
227 | *
|
228 | * @readonly
|
229 | */
|
230 | get date() {
|
231 | return this.originalResponse.date;
|
232 | }
|
233 | /**
|
234 | * The number of committed blocks
|
235 | * present in the blob. This header is returned only for append blobs.
|
236 | *
|
237 | * @readonly
|
238 | */
|
239 | get blobCommittedBlockCount() {
|
240 | return this.originalResponse.blobCommittedBlockCount;
|
241 | }
|
242 | /**
|
243 | * The ETag contains a value that you can use to
|
244 | * perform operations conditionally, in quotes.
|
245 | *
|
246 | * @readonly
|
247 | */
|
248 | get etag() {
|
249 | return this.originalResponse.etag;
|
250 | }
|
251 | /**
|
252 | * The number of tags associated with the blob
|
253 | *
|
254 | * @readonly
|
255 | */
|
256 | get tagCount() {
|
257 | return this.originalResponse.tagCount;
|
258 | }
|
259 | /**
|
260 | * The error code.
|
261 | *
|
262 | * @readonly
|
263 | */
|
264 | get errorCode() {
|
265 | return this.originalResponse.errorCode;
|
266 | }
|
267 | /**
|
268 | * The value of this header is set to
|
269 | * true if the file data and application metadata are completely encrypted
|
270 | * using the specified algorithm. Otherwise, the value is set to false (when
|
271 | * the file is unencrypted, or if only parts of the file/application metadata
|
272 | * are encrypted).
|
273 | *
|
274 | * @readonly
|
275 | */
|
276 | get isServerEncrypted() {
|
277 | return this.originalResponse.isServerEncrypted;
|
278 | }
|
279 | /**
|
280 | * If the blob has a MD5 hash, and if
|
281 | * request contains range header (Range or x-ms-range), this response header
|
282 | * is returned with the value of the whole blob's MD5 value. This value may
|
283 | * or may not be equal to the value returned in Content-MD5 header, with the
|
284 | * latter calculated from the requested range.
|
285 | *
|
286 | * @readonly
|
287 | */
|
288 | get blobContentMD5() {
|
289 | return this.originalResponse.blobContentMD5;
|
290 | }
|
291 | /**
|
292 | * Returns the date and time the file was last
|
293 | * modified. Any operation that modifies the file or its properties updates
|
294 | * the last modified time.
|
295 | *
|
296 | * @readonly
|
297 | */
|
298 | get lastModified() {
|
299 | return this.originalResponse.lastModified;
|
300 | }
|
301 | /**
|
302 | * Returns the UTC date and time generated by the service that indicates the time at which the blob was
|
303 | * last read or written to.
|
304 | *
|
305 | * @readonly
|
306 | */
|
307 | get lastAccessed() {
|
308 | return this.originalResponse.lastAccessed;
|
309 | }
|
310 | /**
|
311 | * A name-value pair
|
312 | * to associate with a file storage object.
|
313 | *
|
314 | * @readonly
|
315 | */
|
316 | get metadata() {
|
317 | return this.originalResponse.metadata;
|
318 | }
|
319 | /**
|
320 | * This header uniquely identifies the request
|
321 | * that was made and can be used for troubleshooting the request.
|
322 | *
|
323 | * @readonly
|
324 | */
|
325 | get requestId() {
|
326 | return this.originalResponse.requestId;
|
327 | }
|
328 | /**
|
329 | * If a client request id header is sent in the request, this header will be present in the
|
330 | * response with the same value.
|
331 | *
|
332 | * @readonly
|
333 | */
|
334 | get clientRequestId() {
|
335 | return this.originalResponse.clientRequestId;
|
336 | }
|
337 | /**
|
338 | * Indicates the version of the Blob service used
|
339 | * to execute the request.
|
340 | *
|
341 | * @readonly
|
342 | */
|
343 | get version() {
|
344 | return this.originalResponse.version;
|
345 | }
|
346 | /**
|
347 | * Indicates the versionId of the downloaded blob version.
|
348 | *
|
349 | * @readonly
|
350 | */
|
351 | get versionId() {
|
352 | return this.originalResponse.versionId;
|
353 | }
|
354 | /**
|
355 | * Indicates whether version of this blob is a current version.
|
356 | *
|
357 | * @readonly
|
358 | */
|
359 | get isCurrentVersion() {
|
360 | return this.originalResponse.isCurrentVersion;
|
361 | }
|
362 | /**
|
363 | * The SHA-256 hash of the encryption key used to encrypt the blob. This value is only returned
|
364 | * when the blob was encrypted with a customer-provided key.
|
365 | *
|
366 | * @readonly
|
367 | */
|
368 | get encryptionKeySha256() {
|
369 | return this.originalResponse.encryptionKeySha256;
|
370 | }
|
371 | /**
|
372 | * If the request is to read a specified range and the x-ms-range-get-content-crc64 is set to
|
373 | * true, then the request returns a crc64 for the range, as long as the range size is less than
|
374 | * or equal to 4 MB. If both x-ms-range-get-content-crc64 & x-ms-range-get-content-md5 is
|
375 | * specified in the same request, it will fail with 400(Bad Request)
|
376 | */
|
377 | get contentCrc64() {
|
378 | return this.originalResponse.contentCrc64;
|
379 | }
|
380 | /**
|
381 | * Object Replication Policy Id of the destination blob.
|
382 | *
|
383 | * @readonly
|
384 | */
|
385 | get objectReplicationDestinationPolicyId() {
|
386 | return this.originalResponse.objectReplicationDestinationPolicyId;
|
387 | }
|
388 | /**
|
389 | * Parsed Object Replication Policy Id, Rule Id(s) and status of the source blob.
|
390 | *
|
391 | * @readonly
|
392 | */
|
393 | get objectReplicationSourceProperties() {
|
394 | return this.originalResponse.objectReplicationSourceProperties;
|
395 | }
|
396 | /**
|
397 | * If this blob has been sealed.
|
398 | *
|
399 | * @readonly
|
400 | */
|
401 | get isSealed() {
|
402 | return this.originalResponse.isSealed;
|
403 | }
|
404 | /**
|
405 | * UTC date/time value generated by the service that indicates the time at which the blob immutability policy will expire.
|
406 | *
|
407 | * @readonly
|
408 | */
|
409 | get immutabilityPolicyExpiresOn() {
|
410 | return this.originalResponse.immutabilityPolicyExpiresOn;
|
411 | }
|
412 | /**
|
413 | * Indicates immutability policy mode.
|
414 | *
|
415 | * @readonly
|
416 | */
|
417 | get immutabilityPolicyMode() {
|
418 | return this.originalResponse.immutabilityPolicyMode;
|
419 | }
|
420 | /**
|
421 | * Indicates if a legal hold is present on the blob.
|
422 | *
|
423 | * @readonly
|
424 | */
|
425 | get legalHold() {
|
426 | return this.originalResponse.legalHold;
|
427 | }
|
428 | /**
|
429 | * The response body as a browser Blob.
|
430 | * Always undefined in node.js.
|
431 | *
|
432 | * @readonly
|
433 | */
|
434 | get contentAsBlob() {
|
435 | return this.originalResponse.blobBody;
|
436 | }
|
437 | /**
|
438 | * The response body as a node.js Readable stream.
|
439 | * Always undefined in the browser.
|
440 | *
|
441 | * It will automatically retry when internal read stream unexpected ends.
|
442 | *
|
443 | * @readonly
|
444 | */
|
445 | get readableStreamBody() {
|
446 | return isNode ? this.blobDownloadStream : undefined;
|
447 | }
|
448 | /**
|
449 | * The HTTP response.
|
450 | */
|
451 | get _response() {
|
452 | return this.originalResponse._response;
|
453 | }
|
454 | }
|
455 | //# sourceMappingURL=BlobDownloadResponse.js.map |
\ | No newline at end of file |