/
BlobClient.ts
4608 lines (4427 loc) · 164 KB
/
BlobClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {
isNode,
TransferProgressEvent,
TokenCredential,
isTokenCredential,
getDefaultProxySettings
} from "@azure/core-http";
import { CanonicalCode } from "@azure/core-tracing";
import {
BlobDownloadResponseModel,
CpkInfo,
DeleteSnapshotsOptionType,
ModifiedAccessConditions,
RehydratePriority,
LeaseAccessConditions,
BlobDownloadOptionalParams,
BlobGetPropertiesResponse,
BlobDeleteResponse,
BlobUndeleteResponse,
BlobHTTPHeaders,
BlobSetHTTPHeadersResponse,
BlobSetMetadataResponse,
BlobCreateSnapshotResponse,
BlobStartCopyFromURLResponse,
BlobAbortCopyFromURLResponse,
BlobCopyFromURLResponse,
BlobSetTierResponse
} from "./generatedModels";
import { AbortSignalLike } from "@azure/abort-controller";
import { BlobDownloadResponse } from "./BlobDownloadResponse";
import { Blob as StorageBlob } from "./generated/src/operations";
import { rangeToString } from "./Range";
import {
BlobRequestConditions,
Metadata,
ensureCpkIfSpecified,
BlockBlobTier,
PremiumPageBlobTier,
toAccessTier
} from "./models";
import { newPipeline, StoragePipelineOptions, Pipeline } from "./Pipeline";
import {
DEFAULT_MAX_DOWNLOAD_RETRY_REQUESTS,
URLConstants,
DEFAULT_BLOB_DOWNLOAD_BLOCK_BYTES,
DevelopmentConnectionString,
DEFAULT_BLOCK_BUFFER_SIZE_BYTES
} from "./utils/constants";
import {
setURLParameter,
extractConnectionStringParts,
appendToURLPath,
getValueInConnString
} from "./utils/utils.common";
import { readStreamToLocalFile } from "./utils/utils.node";
import { StorageSharedKeyCredential } from "./credentials/StorageSharedKeyCredential";
import { AnonymousCredential } from "./credentials/AnonymousCredential";
import { Batch } from "./utils/Batch";
import { streamToBuffer } from "./utils/utils.node";
import { BlobLeaseClient } from "./BlobLeaseClient";
import { createSpan } from "./utils/tracing";
import { HttpRequestBody } from "@azure/core-http";
import {
AppendBlobCreateResponse,
AppendBlobAppendBlockFromUrlResponse,
AppendBlobAppendBlockResponse
} from "./generatedModels";
import { AppendBlob } from "./generated/src/operations";
import { AppendBlobRequestConditions } from "./models";
import { CommonOptions, StorageClient } from "./StorageClient";
import * as fs from "fs";
import { generateUuid, HttpResponse } from "@azure/core-http";
import {
BlockBlobUploadHeaders,
BlockBlobUploadResponse,
BlockBlobStageBlockResponse,
BlockBlobStageBlockFromURLResponse,
BlockBlobCommitBlockListResponse,
BlockBlobGetBlockListResponse,
BlockListType
} from "./generatedModels";
import { BlockBlob } from "./generated/src/operations";
import { Range } from "./Range";
import { generateBlockID } from "./utils/utils.common";
import { fsStat } from "./utils/utils.node";
import {
BLOCK_BLOB_MAX_STAGE_BLOCK_BYTES,
BLOCK_BLOB_MAX_UPLOAD_BLOB_BYTES,
BLOCK_BLOB_MAX_BLOCKS
} from "./utils/constants";
import { BufferScheduler } from "./utils/BufferScheduler";
import { Readable } from "stream";
import {
PageBlobCreateResponse,
PageBlobUploadPagesResponse,
PageBlobUploadPagesFromURLResponse,
PageBlobClearPagesResponse,
PageBlobResizeResponse,
SequenceNumberActionType,
PageBlobUpdateSequenceNumberResponse,
PageBlobCopyIncrementalResponse
} from "./generatedModels";
import { PageBlob } from "./generated/src/operations";
import { PageBlobRequestConditions } from "./models";
import {
PageBlobGetPageRangesDiffResponse,
PageBlobGetPageRangesResponse,
rangeResponseFromModel
} from "./PageBlobRangeResponse";
import {
BlobBeginCopyFromUrlPoller,
BlobBeginCopyFromUrlPollState,
CopyPollerBlobClient
} from "./pollers/BlobStartCopyFromUrlPoller";
import { PollerLike, PollOperationState } from "@azure/core-lro";
/**
* Options to configure the {@link BlobClient.beginCopyFromURL} operation.
*
* @export
* @interface BlobBeginCopyFromURLOptions
*/
export interface BlobBeginCopyFromURLOptions extends BlobStartCopyFromURLOptions {
/**
* The amount of time in milliseconds the poller should wait between
* calls to the service to determine the status of the Blob copy.
* Defaults to 15 seconds.
*
* @type {number}
* @memberof BlobBeginCopyFromURLOptions
*/
intervalInMs?: number;
/**
* Callback to receive the state of the copy progress.
*
* @memberof BlobBeginCopyFromURLOptions
*/
onProgress?: (state: BlobBeginCopyFromUrlPollState) => void;
/**
* Serialized poller state that can be used to resume polling from.
* This may be useful when starting a copy on one process or thread
* and you wish to continue polling on another process or thread.
*
* To get serialized poller state, call `poller.toString()` on an existing
* poller.
*
* @memberof BlobBeginCopyFromURLOptions
*/
resumeFrom?: string;
}
/**
* Contains response data for the {@link BlobClient.beginCopyFromURL} operation.
*
* @export
* @interface BlobBeginCopyFromURLResponse
*/
export interface BlobBeginCopyFromURLResponse extends BlobStartCopyFromURLResponse {}
/**
* Options to configure the {@link BlobClient.download} operation.
*
* @export
* @interface BlobDownloadOptions
*/
export interface BlobDownloadOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobDownloadOptions
*/
abortSignal?: AbortSignalLike;
/**
* An opaque DateTime string value that, when present, specifies the blob snapshot to retrieve.
*
* @type {string}
* @memberof BlobDownloadOptions
*/
snapshot?: string;
/**
* When this is set to true and download range of blob, the service returns the MD5 hash for the range,
* as long as the range is less than or equal to 4 MB in size.
*
* rangeGetContentCrc64 and rangeGetContentMD5 cannot be set at same time.
*
* @type {boolean}
* @memberof BlobDownloadOptions
*/
rangeGetContentMD5?: boolean;
/**
* When this is set to true and download range of blob, the service returns the CRC64 hash for the range,
* as long as the range is less than or equal to 4 MB in size.
*
* rangeGetContentCrc64 and rangeGetContentMD5 cannot be set at same time.
*
* @type {boolean}
* @memberof BlobDownloadOptions
*/
rangeGetContentCrc64?: boolean;
/**
* Conditions to meet when downloading blobs.
*
* @type {BlobRequestConditions}
* @memberof BlobDownloadOptions
*/
conditions?: BlobRequestConditions;
/**
* Call back to receive events on the progress of download operation.
*
* @type {(progress: TransferProgressEvent) => void}
* @memberof BlobDownloadOptions
*/
onProgress?: (progress: TransferProgressEvent) => void;
/**
* Optional. ONLY AVAILABLE IN NODE.JS.
*
* How many retries will perform when original body download stream unexpected ends.
* Above kind of ends will not trigger retry policy defined in a pipeline,
* because they doesn't emit network errors.
*
* With this option, every additional retry means an additional `FileClient.download()` request will be made
* from the broken point, until the requested range has been successfully downloaded or maxRetryRequests is reached.
*
* Default value is 5, please set a larger value when loading large files in poor network.
*
* @type {number}
* @memberof BlobDownloadOptions
*/
maxRetryRequests?: number;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobDownloadOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.exists} operation.
*
* @export
* @interface BlobExistsOptions
*/
export interface BlobExistsOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobExistsOptions
*/
abortSignal?: AbortSignalLike;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobExistsOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.getProperties} operation.
*
* @export
* @interface BlobGetPropertiesOptions
*/
export interface BlobGetPropertiesOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobGetPropertiesOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when getting blob properties.
*
* @type {BlobRequestConditions}
* @memberof BlobGetPropertiesOptions
*/
conditions?: BlobRequestConditions;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobGetPropertiesOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.delete} operation.
*
* @export
* @interface BlobDeleteOptions
*/
export interface BlobDeleteOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobDeleteOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when deleting blobs.
*
* @type {BlobRequestConditions}
* @memberof BlobDeleteOptions
*/
conditions?: BlobRequestConditions;
/**
* Specifies options to delete blobs that have associated snapshots.
* - `include`: Delete the base blob and all of its snapshots.
* - `only`: Delete only the blob's snapshots and not the blob itself.
*
* @type {DeleteSnapshotsOptionType}
* @memberof BlobDeleteOptions
*/
deleteSnapshots?: DeleteSnapshotsOptionType;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobDeleteOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.undelete} operation.
*
* @export
* @interface BlobUndeleteOptions
*/
export interface BlobUndeleteOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobUndeleteOptions
*/
abortSignal?: AbortSignalLike;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobUndeleteOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.setHTTPHeaders} operation.
*
* @export
* @interface BlobSetHTTPHeadersOptions
*/
export interface BlobSetHTTPHeadersOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobSetHTTPHeadersOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when setting blob HTTP headers.
*
* @type {BlobRequestConditions}
* @memberof BlobSetHTTPHeadersOptions
*/
conditions?: BlobRequestConditions;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobSetHTTPHeadersOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.setMetadata} operation.
*
* @export
* @interface BlobSetMetadataOptions
*/
export interface BlobSetMetadataOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobSetMetadataOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when setting blob metadata.
*
* @type {BlobRequestConditions}
* @memberof BlobSetMetadataOptions
*/
conditions?: BlobRequestConditions;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobSetMetadataOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure Blob - Acquire Lease operation.
*
* @export
* @interface BlobAcquireLeaseOptions
*/
export interface BlobAcquireLeaseOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobAcquireLeaseOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when acquiring the lease of a blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobAcquireLeaseOptions
*/
conditions?: ModifiedAccessConditions;
}
/**
* Options to configure Blob - Release Lease operation.
*
* @export
* @interface BlobReleaseLeaseOptions
*/
export interface BlobReleaseLeaseOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobReleaseLeaseOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when releasing the lease of a blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobReleaseLeaseOptions
*/
conditions?: ModifiedAccessConditions;
}
/**
* Options to configure Blob - Renew Lease operation.
*
* @export
* @interface BlobRenewLeaseOptions
*/
export interface BlobRenewLeaseOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobRenewLeaseOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when renewing the lease of a blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobRenewLeaseOptions
*/
conditions?: ModifiedAccessConditions;
}
/**
* Options to configure Blob - Change Lease operation.
*
* @export
* @interface BlobChangeLeaseOptions
*/
export interface BlobChangeLeaseOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobChangeLeaseOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when changing the lease of a blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobChangeLeaseOptions
*/
conditions?: ModifiedAccessConditions;
}
/**
* Options to configure Blob - Break Lease operation.
*
* @export
* @interface BlobBreakLeaseOptions
*/
export interface BlobBreakLeaseOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobBreakLeaseOptions
*/
abortSignal?: AbortSignalLike;
/**
* Conditions to meet when breaking the lease of a blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobBreakLeaseOptions
*/
conditions?: ModifiedAccessConditions;
}
/**
* Options to configure the {@link BlobClient.createSnapshot} operation.
*
* @export
* @interface BlobCreateSnapshotOptions
*/
export interface BlobCreateSnapshotOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobCreateSnapshotOptions
*/
abortSignal?: AbortSignalLike;
/**
* A collection of key-value string pair to associate with the snapshot.
*
* @type {Metadata}
* @memberof BlobCreateSnapshotOptions
*/
metadata?: Metadata;
/**
* Conditions to meet when creating blob snapshots.
*
* @type {BlobRequestConditions}
* @memberof BlobCreateSnapshotOptions
*/
conditions?: BlobRequestConditions;
/**
* Customer Provided Key Info.
*
* @type {CpkInfo}
* @memberof BlobCreateSnapshotOptions
*/
customerProvidedKey?: CpkInfo;
}
/**
* Options to configure the {@link BlobClient.beginCopyFromURL} operation.
*
* @export
* @interface BlobStartCopyFromURLOptions
*/
export interface BlobStartCopyFromURLOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobStartCopyFromURLOptions
*/
abortSignal?: AbortSignalLike;
/**
* A collection of key-value string pair to associate with the blob that are being copied.
*
* @type {Metadata}
* @memberof BlobStartCopyFromURLOptions
*/
metadata?: Metadata;
/**
* Conditions to meet for the destination blob when copying from a URL to the blob.
*
* @type {BlobRequestConditions}
* @memberof BlobStartCopyFromURLOptions
*/
conditions?: BlobRequestConditions;
/**
* Conditions to meet for the source Azure Blob/File when copying from a URL to the blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobStartCopyFromURLOptions
*/
sourceConditions?: ModifiedAccessConditions;
/**
* Access tier.
* More Details - https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers
*
* @type {BlockBlobTier | PremiumPageBlobTier | string}
* @memberof BlobStartCopyFromURLOptions
*/
tier?: BlockBlobTier | PremiumPageBlobTier | string;
/**
* Rehydrate Priority - possible values include 'High', 'Standard'.
* More Details - https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-rehydration#rehydrate-an-archived-blob-to-an-online-tier
*
* @type {RehydratePriority}
* @memberof BlobStartCopyFromURLOptions
*/
rehydratePriority?: RehydratePriority;
}
/**
* Options to configure the {@link BlobClient.abortCopyFromURL} operation.
*
* @export
* @interface BlobAbortCopyFromURLOptions
*/
export interface BlobAbortCopyFromURLOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobAbortCopyFromURLOptions
*/
abortSignal?: AbortSignalLike;
/**
* If specified, contains the lease id that must be matched and lease with this id
* must be active in order for the operation to succeed.
*
* @type {LeaseAccessConditions}
* @memberof BlobAbortCopyFromURLOptions
*/
conditions?: LeaseAccessConditions;
}
/**
* Options to configure the {@link BlobClient.syncCopyFromURL} operation.
*
* @export
* @interface BlobSyncCopyFromURLOptions
*/
export interface BlobSyncCopyFromURLOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobSyncCopyFromURLOptions
*/
abortSignal?: AbortSignalLike;
/**
* A collection of key-value string pair to associate with the snapshot.
*
* @type {Metadata}
* @memberof BlobSyncCopyFromURLOptions
*/
metadata?: Metadata;
/**
* Conditions to meet for the destination blob when copying from a URL to the blob.
*
* @type {BlobRequestConditions}
* @memberof BlobSyncCopyFromURLOptions
*/
conditions?: BlobRequestConditions;
/**
* Conditions to meet for the source Azure Blob/File when copying from a URL to the blob.
*
* @type {ModifiedAccessConditions}
* @memberof BlobSyncCopyFromURLOptions
*/
sourceConditions?: ModifiedAccessConditions;
}
/**
* Options to configure the {@link BlobClient.setAccessTier} operation.
*
* @export
* @interface BlobSetTierOptions
*/
export interface BlobSetTierOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobSetTierOptions
*/
abortSignal?: AbortSignalLike;
/**
* If specified, contains the lease id that must be matched and lease with this id
* must be active in order for the operation to succeed.
*
* @type {LeaseAccessConditions}
* @memberof BlobSetTierOptions
*/
conditions?: LeaseAccessConditions;
/**
* Rehydrate Priority - possible values include 'High', 'Standard'.
* More Details - https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-rehydration#rehydrate-an-archived-blob-to-an-online-tier
*
* @type {RehydratePriority}
* @memberof BlobSetTierOptions
*/
rehydratePriority?: RehydratePriority;
}
/**
* Option interface for the {@link BlobClient.downloadToBuffer} operation.
*
* @export
* @interface BlobDownloadToBufferOptions
*/
export interface BlobDownloadToBufferOptions extends CommonOptions {
/**
* An implementation of the `AbortSignalLike` interface to signal the request to cancel the operation.
* For example, use the @azure/abort-controller to create an `AbortSignal`.
*
* @type {AbortSignalLike}
* @memberof BlobDownloadToBufferOptions
*/
abortSignal?: AbortSignalLike;
/**
* blockSize is the data every request trying to download.
* Must be >= 0, if set to 0 or undefined, blockSize will automatically calculated according
* to the blob size.
*
* @type {number}
* @memberof BlobDownloadToBufferOptions
*/
blockSize?: number;
/**
* Optional. ONLY AVAILABLE IN NODE.JS.
*
* How many retries will perform when original block download stream unexpected ends.
* Above kind of ends will not trigger retry policy defined in a pipeline,
* because they doesn't emit network errors.
*
* With this option, every additional retry means an additional FileClient.download() request will be made
* from the broken point, until the requested block has been successfully downloaded or
* maxRetryRequestsPerBlock is reached.
*
* Default value is 5, please set a larger value when in poor network.
*
* @type {number}
* @memberof BlobDownloadToBufferOptions
*/
maxRetryRequestsPerBlock?: number;
/**
* Progress updater.
*
* @type {(progress: TransferProgressEvent) => void}
* @memberof BlobDownloadToBufferOptions
*/
onProgress?: (progress: TransferProgressEvent) => void;
/**
* Access conditions headers.
*
* @type {BlobRequestConditions}
* @memberof BlobDownloadToBufferOptions
*/
conditions?: BlobRequestConditions;
/**
* Concurrency of parallel download.
*
* @type {number}
* @memberof BlobDownloadToBufferOptions
*/
concurrency?: number;
}
/**
* A BlobClient represents a URL to an Azure Storage blob; the blob may be a block blob,
* append blob, or page blob.
*
* @export
* @class BlobClient
*/
export class BlobClient extends StorageClient {
/**
* blobContext provided by protocol layer.
*
* @private
* @type {Blobs}
* @memberof BlobClient
*/
private blobContext: StorageBlob;
private _name: string;
private _containerName: string;
/**
* The name of the blob.
*/
public get name(): string {
return this._name;
}
/**
* The name of the storage container the blob is associated with.
*/
public get containerName(): string {
return this._containerName;
}
/**
*
* Creates an instance of BlobClient from connection string.
*
* @param {string} connectionString Account connection string or a SAS connection string of an Azure storage account.
* [ Note - Account connection string can only be used in NODE.JS runtime. ]
* Account connection string example -
* `DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=accountKey;EndpointSuffix=core.windows.net`
* SAS connection string example -
* `BlobEndpoint=https://myaccount.blob.core.windows.net/;QueueEndpoint=https://myaccount.queue.core.windows.net/;FileEndpoint=https://myaccount.file.core.windows.net/;TableEndpoint=https://myaccount.table.core.windows.net/;SharedAccessSignature=sasString`
* @param {string} containerName Container name.
* @param {string} blobName Blob name.
* @param {StoragePipelineOptions} [options] Optional. Options to configure the HTTP pipeline.
* @memberof BlobClient
*/
constructor(
connectionString: string,
containerName: string,
blobName: string,
options?: StoragePipelineOptions
);
/**
* Creates an instance of BlobClient.
* This method accepts an encoded URL or non-encoded URL pointing to a blob.
* Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped.
* If a blob name includes ? or %, blob name must be encoded in the URL.
*
* @param {string} url A Client string pointing to Azure Storage blob service, such as
* "https://myaccount.blob.core.windows.net". You can append a SAS
* if using AnonymousCredential, such as "https://myaccount.blob.core.windows.net?sasString".
* @param {StorageSharedKeyCredential | AnonymousCredential | TokenCredential} credential Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
* @param {StoragePipelineOptions} [options] Optional. Options to configure the HTTP pipeline.
* @memberof BlobClient
*/
constructor(
url: string,
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential,
options?: StoragePipelineOptions
);
/**
* Creates an instance of BlobClient.
* This method accepts an encoded URL or non-encoded URL pointing to a blob.
* Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped.
* If a blob name includes ? or %, blob name must be encoded in the URL.
*
* @param {string} url A URL string pointing to Azure Storage blob, such as
* "https://myaccount.blob.core.windows.net/mycontainer/blob".
* You can append a SAS if using AnonymousCredential, such as
* "https://myaccount.blob.core.windows.net/mycontainer/blob?sasString".
* This method accepts an encoded URL or non-encoded URL pointing to a blob.
* Encoded URL string will NOT be escaped twice, only special characters in URL path will be escaped.
* However, if a blob name includes ? or %, blob name must be encoded in the URL.
* Such as a blob named "my?blob%", the URL should be "https://myaccount.blob.core.windows.net/mycontainer/my%3Fblob%25".
* @param {Pipeline} pipeline Call newPipeline() to create a default
* pipeline, or provide a customized pipeline.
* @memberof BlobClient
*/
constructor(url: string, pipeline: Pipeline);
constructor(
urlOrConnectionString: string,
credentialOrPipelineOrContainerName?:
| string
| StorageSharedKeyCredential
| AnonymousCredential
| TokenCredential
| Pipeline,
blobNameOrOptions?: string | StoragePipelineOptions,
options?: StoragePipelineOptions
) {
options = options || {};
let pipeline: Pipeline;
let url: string;
if (credentialOrPipelineOrContainerName instanceof Pipeline) {
// (url: string, pipeline: Pipeline)
url = urlOrConnectionString;
pipeline = credentialOrPipelineOrContainerName;
} else if (
(isNode && credentialOrPipelineOrContainerName instanceof StorageSharedKeyCredential) ||
credentialOrPipelineOrContainerName instanceof AnonymousCredential ||
isTokenCredential(credentialOrPipelineOrContainerName)
) {
// (url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)
url = urlOrConnectionString;
options = blobNameOrOptions as StoragePipelineOptions;
pipeline = newPipeline(credentialOrPipelineOrContainerName, options);
} else if (
!credentialOrPipelineOrContainerName &&
typeof credentialOrPipelineOrContainerName !== "string"
) {
// (url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)
// The second parameter is undefined. Use anonymous credential.
url = urlOrConnectionString;
pipeline = newPipeline(new AnonymousCredential(), options);
} else if (
credentialOrPipelineOrContainerName &&
typeof credentialOrPipelineOrContainerName === "string" &&
blobNameOrOptions &&
typeof blobNameOrOptions === "string"
) {
// (connectionString: string, containerName: string, blobName: string, options?: StoragePipelineOptions)
const containerName = credentialOrPipelineOrContainerName;
const blobName = blobNameOrOptions;
const extractedCreds = extractConnectionStringParts(urlOrConnectionString);
if (extractedCreds.kind === "AccountConnString") {
if (isNode) {
const sharedKeyCredential = new StorageSharedKeyCredential(
extractedCreds.accountName!,
extractedCreds.accountKey
);
url = appendToURLPath(
appendToURLPath(extractedCreds.url, encodeURIComponent(containerName)),
encodeURIComponent(blobName)
);
options.proxyOptions = getDefaultProxySettings(extractedCreds.proxyUri);
pipeline = newPipeline(sharedKeyCredential, options);
} else {
throw new Error("Account connection string is only supported in Node.js environment");
}
} else if (extractedCreds.kind === "SASConnString") {
url =
appendToURLPath(
appendToURLPath(extractedCreds.url, encodeURIComponent(containerName)),
encodeURIComponent(blobName)
) +
"?" +
extractedCreds.accountSas;
pipeline = newPipeline(new AnonymousCredential(), options);
} else {
throw new Error(
"Connection string must be either an Account connection string or a SAS connection string"
);
}
} else {
throw new Error("Expecting non-empty strings for containerName and blobName parameters");
}
super(url, pipeline);
({
blobName: this._name,
containerName: this._containerName
} = this.getBlobAndContainerNamesFromUrl());
this.blobContext = new StorageBlob(this.storageClientContext);
}
/**
* Creates a new BlobClient object identical to the source but with the specified snapshot timestamp.
* Provide "" will remove the snapshot and return a Client to the base blob.
*
* @param {string} snapshot The snapshot timestamp.
* @returns {BlobClient} A new BlobClient object identical to the source but with the specified snapshot timestamp
* @memberof BlobClient
*/
public withSnapshot(snapshot: string): BlobClient {
return new BlobClient(
setURLParameter(
this.url,
URLConstants.Parameters.SNAPSHOT,
snapshot.length === 0 ? undefined : snapshot
),
this.pipeline
);
}