diff --git a/sdk/storage/storage-file/samples/typescript/advanced.ts b/sdk/storage/storage-file/samples/typescript/advanced.ts index 1ed466b0e6f6..577aa86f2f25 100644 --- a/sdk/storage/storage-file/samples/typescript/advanced.ts +++ b/sdk/storage/storage-file/samples/typescript/advanced.ts @@ -37,13 +37,13 @@ async function main() { // Create a share const shareName = `newshare${new Date().getTime()}`; const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); console.log(`Create share ${shareName} successfully`); // Create a directory const directoryName = `newdirectory${new Date().getTime()}`; const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName); - await directoryClient.create(Aborter.none); + await directoryClient.create(); console.log(`Create directory ${directoryName} successfully`); // Upload local file to Azure file parallelly @@ -53,24 +53,24 @@ async function main() { // Parallel uploading with uploadFileToAzureFile in Node.js runtime // uploadFileToAzureFile is only available in Node.js - await uploadFileToAzureFile(Aborter.none, localFilePath, fileClient, { + await uploadFileToAzureFile(localFilePath, fileClient, { rangeSize: 4 * 1024 * 1024, // 4MB range size parallelism: 20, // 20 concurrency - progress: ev => console.log(ev) + progress: (ev) => console.log(ev) }); console.log("uploadFileToAzureFile success"); // Parallel uploading a Readable stream with uploadStreamToAzureFile in Node.js runtime // uploadStreamToAzureFile is only available in Node.js await uploadStreamToAzureFile( - Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins fs.createReadStream(localFilePath), fileSize, fileClient, 4 * 1024 * 1024, 20, { - progress: ev => console.log(ev) + abortSignal: Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins + progress: (ev: any) => console.log(ev) } ); console.log("uploadStreamToAzureFile success"); @@ -79,7 +79,7 @@ async function main() { // Uncomment following code in browsers because uploadBrowserDataToAzureFile is only available in browsers /* const browserFile = document.getElementById("fileinput").files[0]; - await uploadBrowserDataToAzureFile(Aborter.none, browserFile, fileClient, { + await uploadBrowserDataToAzureFile(browserFile, fileClient, { rangeSize: 4 * 1024 * 1024, // 4MB range size parallelism: 20, // 20 concurrency progress: ev => console.log(ev) @@ -89,22 +89,16 @@ async function main() { // Parallel downloading an Azure file into Node.js buffer // downloadAzureFileToBuffer is only available in Node.js const buffer = Buffer.alloc(fileSize); - await downloadAzureFileToBuffer( - Aborter.timeout(30 * 60 * 1000), - buffer, - fileClient, - 0, - undefined, - { - rangeSize: 4 * 1024 * 1024, // 4MB range size - parallelism: 20, // 20 concurrency - progress: ev => console.log(ev) - } - ); + await downloadAzureFileToBuffer(buffer, fileClient, 0, undefined, { + abortSignal: Aborter.timeout(30 * 60 * 1000), + rangeSize: 4 * 1024 * 1024, // 4MB range size + parallelism: 20, // 20 concurrency + progress: (ev) => console.log(ev) + }); console.log("downloadAzureFileToBuffer success"); // Delete share - await shareClient.delete(Aborter.none); + await shareClient.delete(); console.log("deleted share"); } @@ -113,6 +107,6 @@ main() .then(() => { console.log("Successfully executed sample."); }) - .catch(err => { + .catch((err) => { console.log(err.message); }); diff --git a/sdk/storage/storage-file/samples/typescript/basic.ts b/sdk/storage/storage-file/samples/typescript/basic.ts index 3c396a2e1b1f..f34c2a277ce0 100644 --- a/sdk/storage/storage-file/samples/typescript/basic.ts +++ b/sdk/storage/storage-file/samples/typescript/basic.ts @@ -3,14 +3,13 @@ */ import { - Aborter, StorageClient, FileServiceClient, + SharedKeyCredential, + Models, ShareClient, DirectoryClient, - FileClient, - SharedKeyCredential, - Models + FileClient } from "../.."; // Change to "@azure/storage-file" in your package async function main() { @@ -38,7 +37,6 @@ async function main() { let marker; do { const listSharesResponse: Models.ServiceListSharesSegmentResponse = await serviceClient.listSharesSegment( - Aborter.none, marker ); @@ -51,24 +49,24 @@ async function main() { // Create a share const shareName = `newshare${new Date().getTime()}`; const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); console.log(`Create share ${shareName} successfully`); // Create a directory const directoryName = `newdirectory${new Date().getTime()}`; const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName); - await directoryClient.create(Aborter.none); + await directoryClient.create(); console.log(`Create directory ${directoryName} successfully`); // Create a file const content = "Hello World!"; const fileName = "newfile" + new Date().getTime(); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, content.length); + await fileClient.create(content.length); console.log(`Create file ${fileName} successfully`); // Upload file range - await fileClient.uploadRange(Aborter.none, content, 0, content.length); + await fileClient.uploadRange(content, 0, content.length); console.log(`Upload file range "${content}" to ${fileName} successfully`); // List directories and files @@ -76,7 +74,6 @@ async function main() { marker = undefined; do { const listFilesAndDirectoriesResponse: Models.DirectoryListFilesAndDirectoriesSegmentResponse = await directoryClient.listFilesAndDirectoriesSegment( - Aborter.none, marker ); @@ -84,8 +81,7 @@ async function main() { for (const file of listFilesAndDirectoriesResponse.segment.fileItems) { console.log(`\tFile: ${file.name}`); } - for (const directory of listFilesAndDirectoriesResponse.segment - .directoryItems) { + for (const directory of listFilesAndDirectoriesResponse.segment.directoryItems) { console.log(`\tDirectory: ${directory.name}`); } } while (marker); @@ -93,15 +89,13 @@ async function main() { // Get file content from position 0 to the end // In Node.js, get downloaded data by accessing downloadFileResponse.readableStreamBody // In browsers, get downloaded data by accessing downloadFileResponse.blobBody - const downloadFileResponse = await fileClient.download(Aborter.none, 0); + const downloadFileResponse = await fileClient.download(0); console.log( - `Downloaded file content${await streamToString( - downloadFileResponse.readableStreamBody! - )}` + `Downloaded file content${await streamToString(downloadFileResponse.readableStreamBody!)}` ); // Delete share - await shareClient.delete(Aborter.none); + await shareClient.delete(); console.log(`deleted share ${shareName}`); } @@ -109,7 +103,7 @@ async function main() { async function streamToString(readableStream: NodeJS.ReadableStream) { return new Promise((resolve, reject) => { const chunks: string[] = []; - readableStream.on("data", data => { + readableStream.on("data", (data) => { chunks.push(data.toString()); }); readableStream.on("end", () => { @@ -124,6 +118,6 @@ main() .then(() => { console.log("Successfully executed sample."); }) - .catch(err => { + .catch((err) => { console.log(err.message); }); diff --git a/sdk/storage/storage-file/src/Aborter.ts b/sdk/storage/storage-file/src/Aborter.ts index 0302dccdc6fd..a05f9276ff44 100644 --- a/sdk/storage/storage-file/src/Aborter.ts +++ b/sdk/storage/storage-file/src/Aborter.ts @@ -14,18 +14,18 @@ import { AbortSignalLike, isNode } from "@azure/ms-rest-js"; * * @example * // Abort without timeout - * await fileClient.uploadRange(Aborter.none, buf, 0, buf.length); + * await fileClient.uploadRange(buf, 0, buf.length); * * @example * // Abort container create in 1000ms - * await fileClient.uploadRange(Aborter.timeout(1000), buf, 0, buf.length); + * await fileClient.uploadRange(buf, 0, buf.length, {abortSignal: Aborter.timeout(1000)}); * * @example * // Share aborter cross multiple operations in 30s * // Upload the same data to 2 different data centers at the same time, abort another when any of them is finished * const aborter = Aborter.timeout(30 * 1000); - * fileClient1.uploadRange(aborter, buf, 0, buf.length).then(aborter.abort); - * fileClient2.uploadRange(aborter, buf, 0, buf.length).then(aborter.abort); + * fileClient1.uploadRange(buf, 0, buf.length, {abortSignal: aborter}).then(aborter.abort); + * fileClient2.uploadRange(buf, 0, buf.length, {abortSignal: aborter}).then(aborter.abort); * * @example * // Cascaded aborting @@ -33,8 +33,8 @@ import { AbortSignalLike, isNode } from "@azure/ms-rest-js"; * const aborter = Aborter.timeout(30 * 1000); * * // Following 2 operations can't take more than 25 seconds - * await fileClient.uploadRange(aborter.withTimeout(25 * 1000), buf, 0, buf.length); - * await fileClient.uploadRange(aborter.withTimeout(25 * 1000), buf, 0, buf.length); + * await fileClient.uploadRange(buf, 0, buf.length, {abortSignal: aborter.withTimeout(25 * 1000)}); + * await fileClient.uploadRange(buf, 0, buf.length, {abortSignal: aborter.withTimeout(25 * 1000)}); * * @export * @class Aborter diff --git a/sdk/storage/storage-file/src/DirectoryClient.ts b/sdk/storage/storage-file/src/DirectoryClient.ts index 7f1bb74522b8..eea03109662a 100644 --- a/sdk/storage/storage-file/src/DirectoryClient.ts +++ b/sdk/storage/storage-file/src/DirectoryClient.ts @@ -8,6 +8,7 @@ import { StorageClient } from "./StorageClient"; import { appendToURLPath } from "./utils/utils.common"; export interface IDirectoryCreateOptions { + abortSignal?: Aborter; /** * A name-value pair * to associate with a file storage object. @@ -19,6 +20,7 @@ export interface IDirectoryCreateOptions { } export interface IDirectoryListFilesAndDirectoriesSegmentOptions { + abortSignal?: Aborter; /** * Filters the results to return only entries whose * name begins with the specified prefix. @@ -39,6 +41,18 @@ export interface IDirectoryListFilesAndDirectoriesSegmentOptions { maxresults?: number; } +export interface IDirectoryDeleteOptions { + abortSignal?: Aborter; +} + +export interface IDirectoryGetPropertiesOptions { + abortSignal?: Aborter; +} + +export interface IDirectorySetMetadataOptions { + abortSignal?: Aborter; +} + /** * A DirectoryClient represents a URL to the Azure Storage directory allowing you to manipulate its files and directories. * @@ -121,16 +135,14 @@ export class DirectoryClient extends StorageClient { * Creates a new directory under the specified share or parent directory. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-directory * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IDirectoryCreateOptions} [options] * @returns {Promise} * @memberof DirectoryClient */ public async create( - aborter: Aborter, options: IDirectoryCreateOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.create({ ...options, abortSignal: aborter @@ -143,12 +155,13 @@ export class DirectoryClient extends StorageClient { * subdirectories. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-directory-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof DirectoryClient */ - public async getProperties(aborter: Aborter): Promise { + public async getProperties( + options: IDirectoryGetPropertiesOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.getProperties({ abortSignal: aborter }); @@ -159,12 +172,13 @@ export class DirectoryClient extends StorageClient { * deleted. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-directory * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof DirectoryClient */ - public async delete(aborter: Aborter): Promise { + public async delete( + options: IDirectoryDeleteOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.deleteMethod({ abortSignal: aborter }); @@ -174,16 +188,15 @@ export class DirectoryClient extends StorageClient { * Updates user defined metadata for the specified directory. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-directory-metadata * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IMetadata} [metadata] If no metadata provided, all existing directory metadata will be removed * @returns {Promise} * @memberof DirectoryClient */ public async setMetadata( - aborter: Aborter, - metadata?: IMetadata + metadata?: IMetadata, + options: IDirectorySetMetadataOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.setMetadata({ abortSignal: aborter, metadata @@ -195,18 +208,16 @@ export class DirectoryClient extends StorageClient { * contents only for a single level of the directory hierarchy. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/list-directories-and-files * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} [marker] * @param {IDirectoryListFilesAndDirectoriesSegmentOptions} [options] * @returns {Promise} * @memberof DirectoryClient */ public async listFilesAndDirectoriesSegment( - aborter: Aborter, marker?: string, options: IDirectoryListFilesAndDirectoriesSegmentOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.listFilesAndDirectoriesSegment({ abortSignal: aborter, marker, diff --git a/sdk/storage/storage-file/src/FileClient.ts b/sdk/storage/storage-file/src/FileClient.ts index ab4b6024d40c..b4eda862b5d0 100644 --- a/sdk/storage/storage-file/src/FileClient.ts +++ b/sdk/storage/storage-file/src/FileClient.ts @@ -16,6 +16,7 @@ import { import { appendToURLPath } from "./utils/utils.common"; export interface IFileCreateOptions { + abortSignal?: Aborter; /** * File HTTP headers like Content-Type. * @@ -34,7 +35,12 @@ export interface IFileCreateOptions { metadata?: IMetadata; } +export interface IFileDeleteOptions { + abortSignal?: Aborter; +} + export interface IFileDownloadOptions { + abortSignal?: Aborter; /** * Optional. ONLY AVAILABLE IN NODE.JS. * @@ -71,6 +77,7 @@ export interface IFileDownloadOptions { } export interface IFileUploadRangeOptions { + abortSignal?: Aborter; /** * An MD5 hash of the content. This hash is * used to verify the integrity of the data during transport. When the @@ -93,6 +100,7 @@ export interface IFileUploadRangeOptions { } export interface IFileGetRangeListOptions { + abortSignal?: Aborter; /** * Optional. Specifies the range of bytes over which to list ranges, inclusively. * @@ -102,6 +110,10 @@ export interface IFileGetRangeListOptions { range?: IRange; } +export interface IFileGetPropertiesOptions { + abortSignal?: Aborter; +} + /** * Contains response data for the getRangeList operation. */ @@ -133,6 +145,7 @@ export type FileGetRangeListResponse = Models.FileGetRangeListHeaders & { }; export interface IFileStartCopyOptions { + abortSignal?: Aborter; /** * A name-value pair * to associate with a file storage object. @@ -143,6 +156,26 @@ export interface IFileStartCopyOptions { metadata?: IMetadata; } +export interface IFileSetMetadataOptions { + abortSignal?: Aborter; +} + +export interface IFileHTTPHeadersOptions { + abortSignal?: Aborter; +} + +export interface IFileAbortCopyFromURLOptions { + abortSignal?: Aborter; +} + +export interface IFileResizeOptions { + abortSignal?: Aborter; +} + +export interface IFileClearRangeOptions { + abortSignal?: Aborter; +} + /** * A FileClient represents a URL to an Azure Storage file. * @@ -212,18 +245,16 @@ export class FileClient extends StorageClient { * Creates a new file or replaces a file. Note it only initializes the file with no content. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-file * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} size Specifies the maximum size in bytes for the file, up to 1 TB. * @param {IFileCreateOptions} [options] * @returns {Promise} * @memberof FileClient */ public async create( - aborter: Aborter, size: number, options: IFileCreateOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (size < 0 || size > FILE_MAX_SIZE_BYTES) { throw new RangeError(`File size must >= 0 and < ${FILE_MAX_SIZE_BYTES}.`); } @@ -244,8 +275,6 @@ export class FileClient extends StorageClient { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset From which position of the file to download, >= 0 * @param {number} [count] How much data to be downloaded, > 0. Will download to the end when undefined * @param {IFileDownloadOptions} [options] @@ -253,11 +282,11 @@ export class FileClient extends StorageClient { * @memberof FileClient */ public async download( - aborter: Aborter, offset: number, count?: number, options: IFileDownloadOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (options.rangeGetContentMD5 && offset === 0 && count === undefined) { throw new RangeError(`rangeGetContentMD5 only works with partial data downloading`); } @@ -290,7 +319,6 @@ export class FileClient extends StorageClient { } return new FileDownloadResponse( - aborter, res, async (start: number): Promise => { const updatedOptions: Models.FileDownloadOptionalParams = { @@ -315,6 +343,7 @@ export class FileClient extends StorageClient { offset, res.contentLength!, { + abortSignal: aborter, maxRetryRequests: options.maxRetryRequests, progress: options.progress } @@ -326,12 +355,13 @@ export class FileClient extends StorageClient { * for the file. It does not return the content of the file. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof FileClient */ - public async getProperties(aborter: Aborter): Promise { + public async getProperties( + options: IFileGetPropertiesOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.getProperties({ abortSignal: aborter }); @@ -351,12 +381,11 @@ export class FileClient extends StorageClient { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2 * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof FileClient */ - public async delete(aborter: Aborter): Promise { + public async delete(options: IFileDeleteOptions = {}): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.deleteMethod({ abortSignal: aborter }); @@ -369,17 +398,16 @@ export class FileClient extends StorageClient { * these file HTTP headers without a value will be cleared. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {fileHTTPHeaders} [IFileHTTPHeaders] File HTTP headers like Content-Type. * Provide undefined will remove existing HTTP headers. * @returns {Promise} * @memberof FileClient */ public async setHTTPHeaders( - aborter: Aborter, - fileHTTPHeaders: IFileHTTPHeaders = {} + fileHTTPHeaders: IFileHTTPHeaders = {}, + options: IFileHTTPHeadersOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.setHTTPHeaders({ abortSignal: aborter, ...fileHTTPHeaders @@ -391,8 +419,6 @@ export class FileClient extends StorageClient { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} length Resizes a file to the specified size in bytes. * If the specified byte value is less than the current size of the file, * then all ranges above the specified byte value are cleared. @@ -400,9 +426,10 @@ export class FileClient extends StorageClient { * @memberof FileClient */ public async resize( - aborter: Aborter, - length: number + length: number, + options: IFileResizeOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (length < 0) { throw new RangeError(`Size cannot less than 0 when resizing file.`); } @@ -419,16 +446,15 @@ export class FileClient extends StorageClient { * metadata will be removed. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-metadata * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IMetadata} [metadata] If no metadata provided, all existing directory metadata will be removed * @returns {Promise} * @memberof FileClient */ public async setMetadata( - aborter: Aborter, - metadata: IMetadata = {} + metadata: IMetadata = {}, + options: IFileSetMetadataOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.setMetadata({ abortSignal: aborter, metadata @@ -439,8 +465,6 @@ export class FileClient extends StorageClient { * Upload a range of bytes to a file. Both the start and count of the * range must be specified. The range can be up to 4 MB in size. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {HttpRequestBody} body Blob, string, ArrayBuffer, ArrayBufferView or a function * which returns a new Readable stream whose offset is from data source beginning. * @param {number} offset Offset position of the destination Azure File to upload. @@ -451,12 +475,12 @@ export class FileClient extends StorageClient { * @memberof FileClient */ public async uploadRange( - aborter: Aborter, body: HttpRequestBody, offset: number, contentLength: number, options: IFileUploadRangeOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (offset < 0 || contentLength <= 0) { throw new RangeError(`offset must >= 0 and contentLength must be > 0`); } @@ -482,18 +506,17 @@ export class FileClient extends StorageClient { * Clears the specified range and * releases the space used in storage for that range. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} offset * @param {number} contentLength * @returns {Promise} * @memberof FileClient */ public async clearRange( - aborter: Aborter, offset: number, - contentLength: number + contentLength: number, + options: IFileClearRangeOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (offset < 0 || contentLength <= 0) { throw new RangeError(`offset must >= 0 and contentLength must be > 0`); } @@ -506,16 +529,14 @@ export class FileClient extends StorageClient { /** * Returns the list of valid ranges for a file. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IFileGetRangeListOptions} [options] * @returns {Promise} * @memberof FileClient */ public async getRangeList( - aborter: Aborter, options: IFileGetRangeListOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; const originalResponse = await this.context.getRangeList({ abortSignal: aborter, range: options.range ? rangeToString(options.range) : undefined @@ -538,8 +559,6 @@ export class FileClient extends StorageClient { /** * Copies a blob or file to a destination file within the storage account. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} copySource Specifies the URL of the source file or blob, up to 2 KB in length. * To copy a file to another file within the same storage account, you may use Shared Key to * authenticate the source file. If you are copying a file from another storage account, or if you @@ -552,10 +571,10 @@ export class FileClient extends StorageClient { * @memberof FileClient */ public async startCopyFromURL( - aborter: Aborter, copySource: string, options: IFileStartCopyOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.startCopy(copySource, { abortSignal: aborter, metadata: options.metadata @@ -567,16 +586,15 @@ export class FileClient extends StorageClient { * metadata. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/abort-copy-file * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} copyId * @returns {Promise} * @memberof FileClient */ public async abortCopyFromURL( - aborter: Aborter, - copyId: string + copyId: string, + options: IFileAbortCopyFromURLOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.abortCopy(copyId, { abortSignal: aborter }); diff --git a/sdk/storage/storage-file/src/FileDownloadResponse.ts b/sdk/storage/storage-file/src/FileDownloadResponse.ts index 02ea33db42c6..24903ac6c354 100644 --- a/sdk/storage/storage-file/src/FileDownloadResponse.ts +++ b/sdk/storage/storage-file/src/FileDownloadResponse.ts @@ -1,6 +1,4 @@ import { HttpResponse, isNode } from "@azure/ms-rest-js"; - -import { Aborter } from "./Aborter"; import * as Models from "./generated/lib/models"; import { IMetadata } from "./models"; import { @@ -363,7 +361,6 @@ export class FileDownloadResponse implements Models.FileDownloadResponse { /** * Creates an instance of FileDownloadResponse. * - * @param {Aborter} aborter * @param {Models.FileDownloadResponse} originalResponse * @param {ReadableStreamGetter} getter * @param {number} offset @@ -372,7 +369,6 @@ export class FileDownloadResponse implements Models.FileDownloadResponse { * @memberof FileDownloadResponse */ public constructor( - aborter: Aborter, originalResponse: Models.FileDownloadResponse, getter: ReadableStreamGetter, offset: number, @@ -381,7 +377,6 @@ export class FileDownloadResponse implements Models.FileDownloadResponse { ) { this.originalResponse = originalResponse; this.fileDownloadStream = new RetriableReadableStream( - aborter, this.originalResponse.readableStreamBody!, getter, offset, diff --git a/sdk/storage/storage-file/src/FileServiceClient.ts b/sdk/storage/storage-file/src/FileServiceClient.ts index e5b4db3e8ba9..2e0ab3fd7900 100644 --- a/sdk/storage/storage-file/src/FileServiceClient.ts +++ b/sdk/storage/storage-file/src/FileServiceClient.ts @@ -5,6 +5,7 @@ import { Pipeline } from "./Pipeline"; import { StorageClient } from "./StorageClient"; export interface IServiceListSharesSegmentOptions { + abortSignal?: Aborter; /** * Filters the results to return only entries whose * name begins with the specified prefix. @@ -34,6 +35,14 @@ export interface IServiceListSharesSegmentOptions { include?: Models.ListSharesIncludeType[]; } +export interface IServiceGetPropertiesOptions { + abortSignal?: Aborter; +} + +export interface IServiceSetPropertiesOptions { + abortSignal?: Aborter; +} + /** * A FileServiceClient represents a URL to the Azure Storage File service allowing you * to manipulate file shares. @@ -84,12 +93,13 @@ export class FileServiceClient extends StorageClient { * for Storage Analytics and CORS (Cross-Origin Resource Sharing) rules. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties} * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof FileServiceClient */ - public async getProperties(aborter: Aborter): Promise { + public async getProperties( + options: IServiceGetPropertiesOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.serviceContext.getProperties({ abortSignal: aborter }); @@ -100,16 +110,15 @@ export class FileServiceClient extends StorageClient { * for Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and soft delete settings. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties} * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.StorageServiceProperties} properties * @returns {Promise} * @memberof FileServiceClient */ public async setProperties( - aborter: Aborter, - properties: Models.StorageServiceProperties + properties: Models.StorageServiceProperties, + options: IServiceSetPropertiesOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.serviceContext.setProperties(properties, { abortSignal: aborter }); @@ -119,8 +128,6 @@ export class FileServiceClient extends StorageClient { * Gets the properties of a storage account's File service, including properties for Storage * Analytics metrics and CORS (Cross-Origin Resource Sharing) rules. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} [marker] A string value that identifies the portion of * the list to be returned with the next list operation. The operation * returns a marker value within the response body if the list returned was @@ -132,10 +139,10 @@ export class FileServiceClient extends StorageClient { * @memberof FileServiceClient */ public async listSharesSegment( - aborter: Aborter, marker?: string, options: IServiceListSharesSegmentOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.serviceContext.listSharesSegment({ abortSignal: aborter, marker, diff --git a/sdk/storage/storage-file/src/ShareClient.ts b/sdk/storage/storage-file/src/ShareClient.ts index 7d717e1670b0..3bcc38830023 100644 --- a/sdk/storage/storage-file/src/ShareClient.ts +++ b/sdk/storage/storage-file/src/ShareClient.ts @@ -11,6 +11,7 @@ import { URLConstants } from "./utils/constants"; import { appendToURLPath, setURLParameter, truncatedISO8061Date } from "./utils/utils.common"; export interface IShareCreateOptions { + abortSignal?: Aborter; /** * A name-value pair to associate with a file storage object. * @@ -30,6 +31,7 @@ export interface IShareCreateOptions { } export interface IShareDeleteMethodOptions { + abortSignal?: Aborter; /** * Specifies the option * include to delete the base share and all of its snapshots. Possible values @@ -41,6 +43,33 @@ export interface IShareDeleteMethodOptions { deleteSnapshots?: Models.DeleteSnapshotsOptionType; } +export interface IShareSetMetadataOptions { + abortSignal?: Aborter; +} + +export interface IShareSetAccessPolicyOptions { + abortSignal?: Aborter; +} + +export interface IShareGetAccessPolicyOptions { + abortSignal?: Aborter; +} + +export interface IShareGetAccessPolicyOptions { + abortSignal?: Aborter; +} +export interface IShareGetPropertiesOptions { + abortSignal?: Aborter; +} + +export interface IShareSetQuotaOptions { + abortSignal?: Aborter; +} + +export interface IShareGetStatisticsOptions { + abortSignal?: Aborter; +} + export interface ISignedIdentifier { /** * @member {string} id a unique id @@ -89,6 +118,7 @@ export declare type ShareGetAccessPolicyResponse = { }; export interface IShareCreateSnapshotOptions { + abortSignal?: Aborter; /** * A name-value pair to associate with a file storage object. * @@ -180,16 +210,12 @@ export class ShareClient extends StorageClient { * the same name already exists, the operation fails. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/create-share * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IShareCreateOptions} [options] * @returns {Promise} * @memberof ShareClient */ - public async create( - aborter: Aborter, - options: IShareCreateOptions = {} - ): Promise { + public async create(options: IShareCreateOptions = {}): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.create({ ...options, abortSignal: aborter @@ -201,12 +227,13 @@ export class ShareClient extends StorageClient { * share. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-properties * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof ShareClient */ - public async getProperties(aborter: Aborter): Promise { + public async getProperties( + options: IShareGetPropertiesOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.getProperties({ abortSignal: aborter }); @@ -217,16 +244,14 @@ export class ShareClient extends StorageClient { * contained within it are later deleted during garbage collection. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Models.IShareDeleteMethodOptions} [options] * @returns {Promise} * @memberof ShareClient */ public async delete( - aborter: Aborter, options: IShareDeleteMethodOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.deleteMethod({ abortSignal: aborter, ...options @@ -240,16 +265,15 @@ export class ShareClient extends StorageClient { * metadata will be removed. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-metadata * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IMetadata} [metadata] If no metadata provided, all existing directory metadata will be removed * @returns {Promise} * @memberof ShareClient */ public async setMetadata( - aborter: Aborter, - metadata?: IMetadata + metadata?: IMetadata, + options: IShareSetMetadataOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.setMetadata({ abortSignal: aborter, metadata @@ -265,12 +289,13 @@ export class ShareClient extends StorageClient { * * @see https://docs.microsoft.com/en-us/rest/api/storageservices/get-share-acl * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof ShareClient */ - public async getAccessPolicy(aborter: Aborter): Promise { + public async getAccessPolicy( + options: IShareGetAccessPolicyOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; const response = await this.context.getAccessPolicy({ abortSignal: aborter }); @@ -308,16 +333,15 @@ export class ShareClient extends StorageClient { * removed. * @see https://docs.microsoft.com/en-us/rest/api/storageservices/set-share-acl * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {ISignedIdentifier[]} [shareAcl] * @returns {Promise} * @memberof ShareClient */ public async setAccessPolicy( - aborter: Aborter, - shareAcl?: ISignedIdentifier[] + shareAcl?: ISignedIdentifier[], + options: IShareSetAccessPolicyOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; const acl: Models.SignedIdentifier[] = []; for (const identifier of shareAcl || []) { acl.push({ @@ -339,16 +363,14 @@ export class ShareClient extends StorageClient { /** * Creates a read-only snapshot of a share. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {IShareCreateSnapshotOptions} [options={}] * @returns {Promise} * @memberof ShareClient */ public async createSnapshot( - aborter: Aborter, options: IShareCreateSnapshotOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.createSnapshot({ abortSignal: aborter, ...options @@ -358,16 +380,15 @@ export class ShareClient extends StorageClient { /** * Sets quota for the specified share. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {number} quotaInGB Specifies the maximum size of the share in gigabytes * @returns {Promise} * @memberof ShareClient */ public async setQuota( - aborter: Aborter, - quotaInGB: number + quotaInGB: number, + options: IShareSetQuotaOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (quotaInGB <= 0 || quotaInGB > 5120) { throw new RangeError( `Share quota must be greater than 0, and less than or equal to 5Tib (5120GB)` @@ -382,12 +403,13 @@ export class ShareClient extends StorageClient { /** * Retrieves statistics related to the share. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @returns {Promise} * @memberof ShareClient */ - public async getStatistics(aborter: Aborter): Promise { + public async getStatistics( + options: IShareGetStatisticsOptions = {} + ): Promise { + const aborter = options.abortSignal || Aborter.none; return this.context.getStatistics({ abortSignal: aborter }); diff --git a/sdk/storage/storage-file/src/highlevel.browser.ts b/sdk/storage/storage-file/src/highlevel.browser.ts index 06f2d7c29371..0323f5793aad 100644 --- a/sdk/storage/storage-file/src/highlevel.browser.ts +++ b/sdk/storage/storage-file/src/highlevel.browser.ts @@ -10,22 +10,18 @@ import { FILE_RANGE_MAX_SIZE_BYTES, DEFAULT_HIGH_LEVEL_PARALLELISM } from "./uti * Uploads a browser Blob/File/ArrayBuffer/ArrayBufferView object to an Azure File. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Blob | ArrayBuffer | ArrayBufferView} browserData Blob, File, ArrayBuffer or ArrayBufferView * @param {FileClient} fileClient * @param {IUploadToAzureFileOptions} [options] * @returns {Promise} */ export async function uploadBrowserDataToAzureFile( - aborter: Aborter, browserData: Blob | ArrayBuffer | ArrayBufferView, fileClient: FileClient, - options?: IUploadToAzureFileOptions + options: IUploadToAzureFileOptions = {} ): Promise { const browserBlob = new Blob([browserData]); return UploadSeekableBlobToAzureFile( - aborter, (offset: number, size: number): Blob => { return browserBlob.slice(offset, offset + size); }, @@ -41,8 +37,6 @@ export async function uploadBrowserDataToAzureFile( * Uploads a browser Blob object to an Azure file. Requires a blobFactory as the data source, * which need to return a Blob object with the offset and size provided. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {(offset: number, size: number) => Blob} blobFactory * @param {number} size * @param {FileClient} fileClient @@ -50,12 +44,12 @@ export async function uploadBrowserDataToAzureFile( * @returns {Promise} */ async function UploadSeekableBlobToAzureFile( - aborter: Aborter, blobFactory: (offset: number, size: number) => Blob, size: number, fileClient: FileClient, options: IUploadToAzureFileOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (!options.rangeSize) { options.rangeSize = FILE_RANGE_MAX_SIZE_BYTES; } @@ -75,7 +69,8 @@ async function UploadSeekableBlobToAzureFile( } // Create the file - await fileClient.create(aborter, size, { + await fileClient.create(size, { + abortSignal: aborter, fileHTTPHeaders: options.fileHTTPHeaders, metadata: options.metadata }); @@ -90,12 +85,9 @@ async function UploadSeekableBlobToAzureFile( const start = options.rangeSize! * i; const end = i === numBlocks - 1 ? size : start + options.rangeSize!; const contentLength = end - start; - await fileClient.uploadRange( - aborter, - blobFactory(start, contentLength), - start, - contentLength - ); + await fileClient.uploadRange(blobFactory(start, contentLength), start, contentLength, { + abortSignal: aborter + }); // Update progress after block is successfully uploaded to server, in case of block trying // TODO: Hook with convenience layer progress event in finer level transferProgress += contentLength; diff --git a/sdk/storage/storage-file/src/highlevel.common.ts b/sdk/storage/storage-file/src/highlevel.common.ts index 7b35406d5688..e98204df881f 100644 --- a/sdk/storage/storage-file/src/highlevel.common.ts +++ b/sdk/storage/storage-file/src/highlevel.common.ts @@ -1,6 +1,7 @@ import { TransferProgressEvent } from "@azure/ms-rest-js"; import { IFileHTTPHeaders, IMetadata } from "./models"; +import { Aborter } from "./Aborter"; /** * Option interface for uploadFileToAzureFile and uploadSeekableStreamToAzureFile. @@ -9,6 +10,7 @@ import { IFileHTTPHeaders, IMetadata } from "./models"; * @interface IUploadToAzureFileOptions */ export interface IUploadToAzureFileOptions { + abortSignal?: Aborter; /** * RangeSize specifies the range size to use in each parallel upload, * the default (and maximum size) is FILE_RANGE_MAX_SIZE_BYTES. @@ -58,6 +60,7 @@ export interface IUploadToAzureFileOptions { * @interface IDownloadFromAzureFileOptions */ export interface IDownloadFromAzureFileOptions { + abortSignal?: Aborter; /** * When downloading Azure files, download method will try to split large file into small ranges. * Every small range will be downloaded via a separte request. diff --git a/sdk/storage/storage-file/src/highlevel.node.ts b/sdk/storage/storage-file/src/highlevel.node.ts index e397b1bebcdb..4b1ace2c0862 100644 --- a/sdk/storage/storage-file/src/highlevel.node.ts +++ b/sdk/storage/storage-file/src/highlevel.node.ts @@ -16,22 +16,18 @@ import { streamToBuffer } from "./utils/utils.node"; * Uploads a local file to an Azure file. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {string} filePath Full path of local file * @param {FileClient} fileClient FileClient * @param {IUploadToAzureFileOptions} [options] * @returns {(Promise)} */ export async function uploadFileToAzureFile( - aborter: Aborter, filePath: string, fileClient: FileClient, options?: IUploadToAzureFileOptions ): Promise { const size = fs.statSync(filePath).size; return uploadResetableStreamToAzureFile( - aborter, (offset, count) => fs.createReadStream(filePath, { autoClose: true, @@ -52,8 +48,6 @@ export async function uploadFileToAzureFile( * is the offset in the Azure file to be uploaded. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {(offset: number) => NodeJS.ReadableStream} streamFactory Returns a Node.js Readable stream starting * from the offset defined * @param {number} size Size of the Azure file @@ -62,12 +56,12 @@ export async function uploadFileToAzureFile( * @returns {(Promise)} */ async function uploadResetableStreamToAzureFile( - aborter: Aborter, streamFactory: (offset: number, count?: number) => NodeJS.ReadableStream, size: number, fileClient: FileClient, options: IUploadToAzureFileOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (!options.rangeSize) { options.rangeSize = FILE_RANGE_MAX_SIZE_BYTES; } @@ -87,7 +81,8 @@ async function uploadResetableStreamToAzureFile( } // Create the file - await fileClient.create(aborter, size, { + await fileClient.create(size, { + abortSignal: aborter, fileHTTPHeaders: options.fileHTTPHeaders, metadata: options.metadata }); @@ -103,10 +98,12 @@ async function uploadResetableStreamToAzureFile( const end = i === numBlocks - 1 ? size : start + options.rangeSize!; const contentLength = end - start; await fileClient.uploadRange( - aborter, () => streamFactory(start, contentLength), start, - contentLength + contentLength, + { + abortSignal: aborter + } ); // Update progress after block is successfully uploaded to server, in case of block trying transferProgress += contentLength; @@ -126,8 +123,6 @@ async function uploadResetableStreamToAzureFile( * Offset and count are optional, pass 0 for both to download the entire file. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Buffer} buffer Buffer to be fill, must have length larger than count * @param {FileClient} fileClient A FileClient object * @param {number} offset From which position of the Azure File to download @@ -136,13 +131,13 @@ async function uploadResetableStreamToAzureFile( * @returns {Promise} */ export async function downloadAzureFileToBuffer( - aborter: Aborter, buffer: Buffer, fileClient: FileClient, offset: number, count?: number, options: IDownloadFromAzureFileOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (!options.rangeSize) { options.rangeSize = FILE_RANGE_MAX_SIZE_BYTES; } @@ -167,7 +162,7 @@ export async function downloadAzureFileToBuffer( // Customer doesn't specify length, get it if (!count) { - const response = await fileClient.getProperties(aborter); + const response = await fileClient.getProperties({ abortSignal: aborter }); count = response.contentLength! - offset; if (count < 0) { throw new RangeError( @@ -187,7 +182,8 @@ export async function downloadAzureFileToBuffer( for (let off = offset; off < offset + count; off = off + options.rangeSize) { batch.addOperation(async () => { const chunkEnd = off + options.rangeSize! < count! ? off + options.rangeSize! : count!; - const response = await fileClient.download(aborter, off, chunkEnd - off + 1, { + const response = await fileClient.download(off, chunkEnd - off + 1, { + abortSignal: aborter, maxRetryRequests: options.maxRetryRequestsPerRange }); const stream = response.readableStreamBody!; @@ -211,6 +207,7 @@ export async function downloadAzureFileToBuffer( * @interface IUploadStreamToAzureFileOptions */ export interface IUploadStreamToAzureFileOptions { + abortSignal?: Aborter; /** * Azure File HTTP Headers. * @@ -248,8 +245,6 @@ export interface IUploadStreamToAzureFileOptions { * parameter, which will avoid Buffer.concat() operations. * * @export - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {Readable} stream Node.js Readable stream. Must be less or equal than file size. * @param {number} size Size of file to be created. Maxium size allowed is 1TB. * If this value is larger than stream size, there will be empty bytes in file tail. @@ -262,7 +257,6 @@ export interface IUploadStreamToAzureFileOptions { * @returns {Promise} */ export async function uploadStreamToAzureFile( - aborter: Aborter, stream: Readable, size: number, fileClient: FileClient, @@ -270,6 +264,7 @@ export async function uploadStreamToAzureFile( maxBuffers: number, options: IUploadStreamToAzureFileOptions = {} ): Promise { + const aborter = options.abortSignal || Aborter.none; if (!options.fileHTTPHeaders) { options.fileHTTPHeaders = {}; } @@ -283,7 +278,8 @@ export async function uploadStreamToAzureFile( } // Create the file - await fileClient.create(aborter, size, { + await fileClient.create(size, { + abortSignal: aborter, fileHTTPHeaders: options.fileHTTPHeaders, metadata: options.metadata }); @@ -301,7 +297,7 @@ export async function uploadStreamToAzureFile( ); } - await fileClient.uploadRange(aborter, buffer, offset!, buffer.length); + await fileClient.uploadRange(buffer, offset!, buffer.length, { abortSignal: aborter }); // Update progress after block is successfully uploaded to server, in case of block trying transferProgress += buffer.length; diff --git a/sdk/storage/storage-file/src/utils/RetriableReadableStream.ts b/sdk/storage/storage-file/src/utils/RetriableReadableStream.ts index 2469955d3220..d99ac87b13a3 100644 --- a/sdk/storage/storage-file/src/utils/RetriableReadableStream.ts +++ b/sdk/storage/storage-file/src/utils/RetriableReadableStream.ts @@ -5,6 +5,7 @@ import { Aborter } from "../Aborter"; export type ReadableStreamGetter = (offset: number) => Promise; export interface IRetriableReadableStreamOptions { + abortSignal?: Aborter; /** * Max retry count (>=0), undefined or invalid value means no retry * @@ -58,8 +59,6 @@ export class RetriableReadableStream extends Readable { /** * Creates an instance of RetriableReadableStream. * - * @param {Aborter} aborter Create a new Aborter instance with Aborter.none or Aborter.timeout(), - * goto documents of Aborter for more examples about request cancellation * @param {NodeJS.ReadableStream} source The current ReadableStream returned from getter * @param {ReadableStreamGetter} getter A method calling downloading request returning * a new ReadableStream from specified offset @@ -69,7 +68,6 @@ export class RetriableReadableStream extends Readable { * @memberof RetriableReadableStream */ public constructor( - aborter: Aborter, source: NodeJS.ReadableStream, getter: ReadableStreamGetter, offset: number, @@ -77,6 +75,7 @@ export class RetriableReadableStream extends Readable { options: IRetriableReadableStreamOptions = {} ) { super(); + const aborter = options.abortSignal || Aborter.none; this.aborter = aborter; this.getter = getter; this.source = source; diff --git a/sdk/storage/storage-file/test/aborter.spec.ts b/sdk/storage/storage-file/test/aborter.spec.ts index fe3c873052f6..4322193c1844 100644 --- a/sdk/storage/storage-file/test/aborter.spec.ts +++ b/sdk/storage/storage-file/test/aborter.spec.ts @@ -23,13 +23,13 @@ describe("Aborter", () => { }); it("Should not abort after calling abort()", async () => { - await shareClient.create(Aborter.none); - await shareClient.delete(Aborter.none); + await shareClient.create(); + await shareClient.delete(); }); it("Should abort when calling abort() before request finishes", async () => { const aborter = Aborter.none; - const response = shareClient.create(aborter); + const response = shareClient.create({ abortSignal: aborter }); aborter.abort(); try { await response; @@ -39,13 +39,13 @@ describe("Aborter", () => { it("Should not abort when calling abort() after request finishes", async () => { const aborter = Aborter.none; - await shareClient.create(aborter); + await shareClient.create(); aborter.abort(); }); it("Should abort after aborter timeout", async () => { try { - await shareClient.create(Aborter.timeout(1)); + await shareClient.create({ abortSignal: Aborter.timeout(1) }); assert.fail(); } catch (err) {} }); @@ -53,7 +53,7 @@ describe("Aborter", () => { it("Should abort after parent aborter calls abort()", async () => { try { const aborter = Aborter.none; - const response = shareClient.create(aborter.withTimeout(10 * 60 * 1000)); + const response = shareClient.create({ abortSignal: aborter.withTimeout(10 * 60 * 1000) }); aborter.abort(); await response; assert.fail(); @@ -63,7 +63,7 @@ describe("Aborter", () => { it("Should abort after parent aborter timeout", async () => { try { const aborter = Aborter.timeout(1); - const response = shareClient.create(aborter.withTimeout(10 * 60 * 1000)); + const response = shareClient.create({ abortSignal: aborter.withTimeout(10 * 60 * 1000) }); await response; assert.fail(); } catch (err) {} diff --git a/sdk/storage/storage-file/test/directoryclient.spec.ts b/sdk/storage/storage-file/test/directoryclient.spec.ts index ad542441ebc0..2c220531dd57 100644 --- a/sdk/storage/storage-file/test/directoryclient.spec.ts +++ b/sdk/storage/storage-file/test/directoryclient.spec.ts @@ -1,6 +1,4 @@ import * as assert from "assert"; - -import { Aborter } from "../src/Aborter"; import { DirectoryClient } from "../src/DirectoryClient"; import { FileClient } from "../src/FileClient"; import { ShareClient } from "../src/ShareClient"; @@ -18,16 +16,16 @@ describe("DirectoryClient", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); dirName = getUniqueName("dir"); dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); }); afterEach(async () => { - await dirClient.delete(Aborter.none); - await shareClient.delete(Aborter.none); + await dirClient.delete(); + await shareClient.delete(); }); it("setMetadata", async () => { @@ -37,9 +35,9 @@ describe("DirectoryClient", () => { keyb: "valb" }; try { - await dirClient.setMetadata(Aborter.none, metadata); + await dirClient.setMetadata(metadata); - const result = await dirClient.getProperties(Aborter.none); + const result = await dirClient.getProperties(); assert.deepEqual(result.metadata, metadata); } catch (err) { console.log(err); @@ -47,7 +45,7 @@ describe("DirectoryClient", () => { }); it("getProperties", async () => { - const result = await dirClient.getProperties(Aborter.none); + const result = await dirClient.getProperties(); assert.ok(result.eTag!.length > 0); assert.ok(result.lastModified); assert.ok(result.requestId); @@ -63,8 +61,8 @@ describe("DirectoryClient", () => { it("create with all parameters configured", async () => { const cClient = ShareClient.fromFileServiceClient(serviceClient, getUniqueName(shareName)); const metadata = { key: "value" }; - await cClient.create(Aborter.none, { metadata }); - const result = await cClient.getProperties(Aborter.none); + await cClient.create({ metadata }); + const result = await cClient.getProperties(); assert.deepStrictEqual(result.metadata, metadata); }); @@ -83,7 +81,7 @@ describe("DirectoryClient", () => { rootDirClient, getUniqueName(`${prefix}dir${i}`) ); - await subDirClient.create(Aborter.none); + await subDirClient.create(); subDirClients.push(subDirClient); } @@ -93,11 +91,11 @@ describe("DirectoryClient", () => { rootDirClient, getUniqueName(`${prefix}file${i}`) ); - await subFileClient.create(Aborter.none, 1024); + await subFileClient.create(1024); subFileClients.push(subFileClient); } - const result = await rootDirClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + const result = await rootDirClient.listFilesAndDirectoriesSegment(undefined, { prefix }); assert.ok(result.serviceEndpoint.length > 0); @@ -117,10 +115,10 @@ describe("DirectoryClient", () => { } for (const subFile of subFileClients) { - await subFile.delete(Aborter.none); + await subFile.delete(); } for (const subDir of subDirClients) { - await subDir.delete(Aborter.none); + await subDir.delete(); } }); @@ -134,7 +132,7 @@ describe("DirectoryClient", () => { rootDirClient, getUniqueName(`${prefix}dir${i}`) ); - await subDirClient.create(Aborter.none); + await subDirClient.create(); subDirClients.push(subDirClient); } @@ -144,21 +142,17 @@ describe("DirectoryClient", () => { rootDirClient, getUniqueName(`${prefix}file${i}`) ); - await subFileClient.create(Aborter.none, 1024); + await subFileClient.create(1024); subFileClients.push(subFileClient); } const firstRequestSize = Math.ceil((subDirClients.length + subFileClients.length) / 2); const secondRequestSize = subDirClients.length + subFileClients.length - firstRequestSize; - const firstResult = await rootDirClient.listFilesAndDirectoriesSegment( - Aborter.none, - undefined, - { - prefix, - maxresults: firstRequestSize - } - ); + const firstResult = await rootDirClient.listFilesAndDirectoriesSegment(undefined, { + prefix, + maxresults: firstRequestSize + }); assert.deepStrictEqual( firstResult.segment.directoryItems.length + firstResult.segment.fileItems.length, @@ -167,7 +161,6 @@ describe("DirectoryClient", () => { assert.notDeepEqual(firstResult.nextMarker, undefined); const secondResult = await rootDirClient.listFilesAndDirectoriesSegment( - Aborter.none, firstResult.nextMarker, { prefix, maxresults: firstRequestSize + secondRequestSize } ); @@ -177,10 +170,10 @@ describe("DirectoryClient", () => { ); for (const subFile of subFileClients) { - await subFile.delete(Aborter.none); + await subFile.delete(); } for (const subDir of subDirClients) { - await subDir.delete(Aborter.none); + await subDir.delete(); } }); }); diff --git a/sdk/storage/storage-file/test/fileclient.spec.ts b/sdk/storage/storage-file/test/fileclient.spec.ts index 1537e0c77dda..7397a3d2040c 100644 --- a/sdk/storage/storage-file/test/fileclient.spec.ts +++ b/sdk/storage/storage-file/test/fileclient.spec.ts @@ -1,12 +1,11 @@ import * as assert from "assert"; import { isNode } from "@azure/ms-rest-js"; - -import { Aborter } from "../src/Aborter"; import { DirectoryClient } from "../src/DirectoryClient"; import { FileClient } from "../src/FileClient"; import { ShareClient } from "../src/ShareClient"; import { bodyToString, getBSU, getUniqueName, sleep } from "./utils"; import * as dotenv from "dotenv"; +import { Aborter } from "../src"; dotenv.config({ path: "../.env" }); describe("FileClient", () => { @@ -22,23 +21,23 @@ describe("FileClient", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); dirName = getUniqueName("dir"); dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); fileName = getUniqueName("file"); fileClient = FileClient.fromDirectoryClient(dirClient, fileName); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("create with default parameters", async () => { - await fileClient.create(Aborter.none, content.length); - const result = await fileClient.download(Aborter.none, 0); + await fileClient.create(content.length); + const result = await fileClient.download(0); assert.deepStrictEqual( await bodyToString(result, content.length), "\u0000".repeat(content.length) @@ -59,12 +58,12 @@ describe("FileClient", () => { key2: "valb" } }; - await fileClient.create(Aborter.none, 512, options); + await fileClient.create(512, options); - const result = await fileClient.download(Aborter.none, 0); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, 512), "\u0000".repeat(512)); - const properties = await fileClient.getProperties(Aborter.none); + const properties = await fileClient.getProperties(); assert.equal(properties.cacheControl, options.fileHTTPHeaders.fileCacheControl); assert.equal(properties.contentDisposition, options.fileHTTPHeaders.fileContentDisposition); assert.equal(properties.contentEncoding, options.fileHTTPHeaders.fileContentEncoding); @@ -75,35 +74,35 @@ describe("FileClient", () => { }); it("setMetadata with new metadata set", async () => { - await fileClient.create(Aborter.none, content.length); + await fileClient.create(content.length); const metadata = { a: "a", b: "b" }; - await fileClient.setMetadata(Aborter.none, metadata); - const result = await fileClient.getProperties(Aborter.none); + await fileClient.setMetadata(metadata); + const result = await fileClient.getProperties(); assert.deepStrictEqual(result.metadata, metadata); }); it("setMetadata with cleaning up metadata", async () => { - await fileClient.create(Aborter.none, content.length); + await fileClient.create(content.length); const metadata = { a: "a", b: "b" }; - await fileClient.setMetadata(Aborter.none, metadata); - const result = await fileClient.getProperties(Aborter.none); + await fileClient.setMetadata(metadata); + const result = await fileClient.getProperties(); assert.deepStrictEqual(result.metadata, metadata); - await fileClient.setMetadata(Aborter.none); - const result2 = await fileClient.getProperties(Aborter.none); + await fileClient.setMetadata(); + const result2 = await fileClient.getProperties(); assert.deepStrictEqual(result2.metadata, {}); }); it("setHTTPHeaders with default parameters", async () => { - await fileClient.create(Aborter.none, content.length); - await fileClient.setHTTPHeaders(Aborter.none, {}); - const result = await fileClient.getProperties(Aborter.none); + await fileClient.create(content.length); + await fileClient.setHTTPHeaders({}); + const result = await fileClient.getProperties(); assert.ok(result.lastModified); assert.deepStrictEqual(result.metadata, {}); @@ -116,7 +115,7 @@ describe("FileClient", () => { }); it("setHTTPHeaders with all parameters set", async () => { - await fileClient.create(Aborter.none, content.length); + await fileClient.create(content.length); const headers = { fileCacheControl: "fileCacheControl", fileContentDisposition: "fileContentDisposition", @@ -125,8 +124,8 @@ describe("FileClient", () => { fileContentMD5: isNode ? Buffer.from([1, 2, 3, 4]) : new Uint8Array([1, 2, 3, 4]), fileContentType: "fileContentType" }; - await fileClient.setHTTPHeaders(Aborter.none, headers); - const result = await fileClient.getProperties(Aborter.none); + await fileClient.setHTTPHeaders(headers); + const result = await fileClient.getProperties(); assert.ok(result.lastModified); assert.deepStrictEqual(result.metadata, {}); assert.deepStrictEqual(result.cacheControl, headers.fileCacheControl); @@ -138,32 +137,32 @@ describe("FileClient", () => { }); it("delete", async () => { - await fileClient.create(Aborter.none, content.length); - await fileClient.delete(Aborter.none); + await fileClient.create(content.length); + await fileClient.delete(); }); it("startCopyFromURL", async () => { - await fileClient.create(Aborter.none, 1024); + await fileClient.create(1024); const newFileClient = FileClient.fromDirectoryClient(dirClient, getUniqueName("copiedfile")); - const result = await newFileClient.startCopyFromURL(Aborter.none, fileClient.url); + const result = await newFileClient.startCopyFromURL(fileClient.url); assert.ok(result.copyId); - const properties1 = await fileClient.getProperties(Aborter.none); - const properties2 = await newFileClient.getProperties(Aborter.none); + const properties1 = await fileClient.getProperties(); + const properties2 = await newFileClient.getProperties(); assert.deepStrictEqual(properties1.contentMD5, properties2.contentMD5); assert.deepStrictEqual(properties2.copyId, result.copyId); assert.deepStrictEqual(properties2.copySource, fileClient.url); }); it("abortCopyFromURL should failed for a completed copy operation", async () => { - await fileClient.create(Aborter.none, content.length); + await fileClient.create(content.length); const newFileClient = FileClient.fromDirectoryClient(dirClient, getUniqueName("copiedfile")); - const result = await newFileClient.startCopyFromURL(Aborter.none, fileClient.url); + const result = await newFileClient.startCopyFromURL(fileClient.url); assert.ok(result.copyId); sleep(1 * 1000); try { - await newFileClient.abortCopyFromURL(Aborter.none, result.copyId!); + await newFileClient.abortCopyFromURL(result.copyId!); assert.fail( "AbortCopyFromURL should be failed and throw exception for an completed copy operation." ); @@ -173,26 +172,26 @@ describe("FileClient", () => { }); it("resize", async () => { - await fileClient.create(Aborter.none, content.length); - const properties = await fileClient.getProperties(Aborter.none); + await fileClient.create(content.length); + const properties = await fileClient.getProperties(); assert.deepStrictEqual(properties.contentLength, content.length); - await fileClient.resize(Aborter.none, 1); - const updatedProperties = await fileClient.getProperties(Aborter.none); + await fileClient.resize(1); + const updatedProperties = await fileClient.getProperties(); assert.deepStrictEqual(updatedProperties.contentLength, 1); }); it("uploadRange", async () => { - await fileClient.create(Aborter.none, 10); - await fileClient.uploadRange(Aborter.none, "Hello", 0, 5); - await fileClient.uploadRange(Aborter.none, "World", 5, 5); - const response = await fileClient.download(Aborter.none, 0, 8); + await fileClient.create(10); + await fileClient.uploadRange("Hello", 0, 5); + await fileClient.uploadRange("World", 5, 5); + const response = await fileClient.download(0, 8); assert.deepStrictEqual(await bodyToString(response, 8), "HelloWor"); }); it("uploadRange with conent MD5", async () => { - await fileClient.create(Aborter.none, 10); - await fileClient.uploadRange(Aborter.none, "Hello", 0, 5, { + await fileClient.create(10); + await fileClient.uploadRange("Hello", 0, 5, { contentMD5: new Uint8Array([ 0x8b, 0x1a, @@ -212,15 +211,15 @@ describe("FileClient", () => { 0xd7 ]) }); - await fileClient.uploadRange(Aborter.none, "World", 5, 5); - const response = await fileClient.download(Aborter.none, 0, 8); + await fileClient.uploadRange("World", 5, 5); + const response = await fileClient.download(0, 8); assert.deepStrictEqual(await bodyToString(response, 8), "HelloWor"); }); it("uploadRange with progress event", async () => { - await fileClient.create(Aborter.none, 10); + await fileClient.create(10); let progressUpdated = false; - await fileClient.uploadRange(Aborter.none, "HelloWorld", 0, 10, { + await fileClient.uploadRange("HelloWorld", 0, 10, { progress: () => { progressUpdated = true; } @@ -229,57 +228,57 @@ describe("FileClient", () => { }); it("clearRange", async () => { - await fileClient.create(Aborter.none, 10); - await fileClient.uploadRange(Aborter.none, "Hello", 0, 5); - await fileClient.uploadRange(Aborter.none, "World", 5, 5); - await fileClient.clearRange(Aborter.none, 1, 8); + await fileClient.create(10); + await fileClient.uploadRange("Hello", 0, 5); + await fileClient.uploadRange("World", 5, 5); + await fileClient.clearRange(1, 8); - const result = await fileClient.download(Aborter.none, 0); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, 10), "H" + "\u0000".repeat(8) + "d"); }); it("getRangeList", async () => { - await fileClient.create(Aborter.none, 10); - await fileClient.uploadRange(Aborter.none, "Hello", 0, 5); - await fileClient.uploadRange(Aborter.none, "World", 5, 5); - await fileClient.clearRange(Aborter.none, 1, 8); + await fileClient.create(10); + await fileClient.uploadRange("Hello", 0, 5); + await fileClient.uploadRange("World", 5, 5); + await fileClient.clearRange(1, 8); - const result = await fileClient.getRangeList(Aborter.none); + const result = await fileClient.getRangeList(); assert.deepStrictEqual(result.rangeList.length, 1); assert.deepStrictEqual(result.rangeList[0], { start: 0, end: 9 }); }); it("download with with default parameters", async () => { - await fileClient.create(Aborter.none, content.length); - await fileClient.uploadRange(Aborter.none, content, 0, content.length); - const result = await fileClient.download(Aborter.none, 0); + await fileClient.create(content.length); + await fileClient.uploadRange(content, 0, content.length); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, content.length), content); }); it("download all parameters set", async () => { - await fileClient.create(Aborter.none, content.length); - await fileClient.uploadRange(Aborter.none, content, 0, content.length); - const result = await fileClient.download(Aborter.none, 0, 1, { + await fileClient.create(content.length); + await fileClient.uploadRange(content, 0, content.length); + const result = await fileClient.download(0, 1, { rangeGetContentMD5: true }); assert.deepStrictEqual(await bodyToString(result, 1), content[0]); }); it("download partial content", async () => { - await fileClient.create(Aborter.none, 10); - await fileClient.uploadRange(Aborter.none, "HelloWorld", 0, 10); + await fileClient.create(10); + await fileClient.uploadRange("HelloWorld", 0, 10); - const result = await fileClient.download(Aborter.none, 0, 2); + const result = await fileClient.download(0, 2); assert.deepStrictEqual(await bodyToString(result, 2), "He"); }); it("download should update progress and abort successfully", async () => { - await fileClient.create(Aborter.none, 128 * 1024 * 1024); + await fileClient.create(128 * 1024 * 1024); let eventTriggered = false; try { const aborter = Aborter.none; - const result = await fileClient.download(aborter, 0, undefined, { + const result = await fileClient.download(0, undefined, { progress: () => { eventTriggered = true; aborter.abort(); diff --git a/sdk/storage/storage-file/test/fileserviceclient.spec.ts b/sdk/storage/storage-file/test/fileserviceclient.spec.ts index 0ea887863942..e2b9e3d61837 100644 --- a/sdk/storage/storage-file/test/fileserviceclient.spec.ts +++ b/sdk/storage/storage-file/test/fileserviceclient.spec.ts @@ -1,6 +1,4 @@ import * as assert from "assert"; - -import { Aborter } from "../src/Aborter"; import { ShareClient } from "../src/ShareClient"; import { getBSU, getUniqueName, wait } from "./utils"; import * as dotenv from "dotenv"; @@ -9,7 +7,7 @@ dotenv.config({ path: "../.env" }); describe("FileServiceClient", () => { it("ListShares with default parameters", async () => { const serviceClient = getBSU(); - const result = await serviceClient.listSharesSegment(Aborter.none); + const result = await serviceClient.listSharesSegment(); assert.ok(typeof result.requestId); assert.ok(result.requestId!.length > 0); @@ -35,10 +33,10 @@ describe("FileServiceClient", () => { const shareName2 = `${shareNamePrefix}x2`; const shareClient1 = ShareClient.fromFileServiceClient(serviceClient, shareName1); const shareClient2 = ShareClient.fromFileServiceClient(serviceClient, shareName2); - await shareClient1.create(Aborter.none, { metadata: { key: "val" } }); - await shareClient2.create(Aborter.none, { metadata: { key: "val" } }); + await shareClient1.create({ metadata: { key: "val" } }); + await shareClient2.create({ metadata: { key: "val" } }); - const result1 = await serviceClient.listSharesSegment(Aborter.none, undefined, { + const result1 = await serviceClient.listSharesSegment(undefined, { include: ["metadata", "snapshots"], maxresults: 1, prefix: shareNamePrefix @@ -51,7 +49,7 @@ describe("FileServiceClient", () => { assert.ok(result1.shareItems![0].properties.lastModified); assert.deepEqual(result1.shareItems![0].metadata!.key, "val"); - const result2 = await serviceClient.listSharesSegment(Aborter.none, result1.nextMarker, { + const result2 = await serviceClient.listSharesSegment(result1.nextMarker, { include: ["metadata", "snapshots"], maxresults: 1, prefix: shareNamePrefix @@ -64,13 +62,13 @@ describe("FileServiceClient", () => { assert.ok(result2.shareItems![0].properties.lastModified); assert.deepEqual(result2.shareItems![0].metadata!.key, "val"); - await shareClient1.delete(Aborter.none); - await shareClient2.delete(Aborter.none); + await shareClient1.delete(); + await shareClient2.delete(); }); it("GetProperties", async () => { const serviceClient = getBSU(); - const result = await serviceClient.getProperties(Aborter.none); + const result = await serviceClient.getProperties(); assert.ok(typeof result.requestId); assert.ok(result.requestId!.length > 0); @@ -89,7 +87,7 @@ describe("FileServiceClient", () => { it("SetProperties", async () => { const serviceClient = getBSU(); - const serviceProperties = await serviceClient.getProperties(Aborter.none); + const serviceProperties = await serviceClient.getProperties(); serviceProperties.minuteMetrics = { enabled: true, @@ -124,10 +122,10 @@ describe("FileServiceClient", () => { serviceProperties.cors.push(newCORS); } - await serviceClient.setProperties(Aborter.none, serviceProperties); + await serviceClient.setProperties(serviceProperties); await wait(5 * 1000); - const result = await serviceClient.getProperties(Aborter.none); + const result = await serviceClient.getProperties(); assert.ok(typeof result.requestId); assert.ok(result.requestId!.length > 0); assert.ok(typeof result.version); diff --git a/sdk/storage/storage-file/test/node/fileclient.spec.ts b/sdk/storage/storage-file/test/node/fileclient.spec.ts index a79de2ec9fdf..78ee1fc9c310 100644 --- a/sdk/storage/storage-file/test/node/fileclient.spec.ts +++ b/sdk/storage/storage-file/test/node/fileclient.spec.ts @@ -1,7 +1,5 @@ import * as assert from "assert"; import { Duplex } from "stream"; - -import { Aborter } from "../../src/Aborter"; import { DirectoryClient } from "../../src/DirectoryClient"; import { FileClient } from "../../src/FileClient"; import { ShareClient } from "../../src/ShareClient"; @@ -20,36 +18,35 @@ describe("BlockBlobURL Node.js only", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); dirName = getUniqueName("dir"); dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); fileName = getUniqueName("file"); fileClient = FileClient.fromDirectoryClient(dirClient, fileName); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("upload with buffer and default parameters", async () => { const body: string = getUniqueName("randomstring"); const bodyBuffer = Buffer.from(body); - await fileClient.create(Aborter.none, body.length); - await fileClient.uploadRange(Aborter.none, bodyBuffer, 0, body.length); - const result = await fileClient.download(Aborter.none, 0); + await fileClient.create(body.length); + await fileClient.uploadRange(bodyBuffer, 0, body.length); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, body.length), body); }); it("upload with Node.js stream", async () => { const body: string = getUniqueName("randomstring"); - await fileClient.create(Aborter.none, body.length); + await fileClient.create(body.length); await fileClient.uploadRange( - Aborter.none, () => { const duplexStream = new Duplex(); duplexStream.push(body); @@ -59,7 +56,7 @@ describe("BlockBlobURL Node.js only", () => { 0, body.length ); - const result = await fileClient.download(Aborter.none, 0); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, body.length), body); }); @@ -67,9 +64,9 @@ describe("BlockBlobURL Node.js only", () => { const body: string = getUniqueName("randomstring你好"); const bodyLength = Buffer.byteLength(body); - await fileClient.create(Aborter.none, bodyLength); - await fileClient.uploadRange(Aborter.none, body, 0, bodyLength); - const result = await fileClient.download(Aborter.none, 0); + await fileClient.create(bodyLength); + await fileClient.uploadRange(body, 0, bodyLength); + const result = await fileClient.download(0); assert.deepStrictEqual(await bodyToString(result, bodyLength), body); }); }); diff --git a/sdk/storage/storage-file/test/node/highlevel.node.spec.ts b/sdk/storage/storage-file/test/node/highlevel.node.spec.ts index db49c852e27c..c97ed9f24514 100644 --- a/sdk/storage/storage-file/test/node/highlevel.node.spec.ts +++ b/sdk/storage/storage-file/test/node/highlevel.node.spec.ts @@ -31,16 +31,16 @@ describe("Highlevel", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); dirName = getUniqueName("dir"); dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); fileName = getUniqueName("file"); fileClient = FileClient.fromDirectoryClient(dirClient, fileName); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); before(async () => { @@ -59,12 +59,12 @@ describe("Highlevel", () => { }); it("uploadFileToAzureFile should success for large data", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileLarge, fileClient, { + await uploadFileToAzureFile(tempFileLarge, fileClient, { parallelism: 20, rangeSize: 4 * 1024 * 1024 }); - const downloadResponse = await fileClient.download(Aborter.none, 0); + const downloadResponse = await fileClient.download(0); const downloadedFile = path.join(tempFolderPath, getUniqueName("downloadfile.")); await readStreamToLocalFile(downloadResponse.readableStreamBody!, downloadedFile); @@ -76,12 +76,12 @@ describe("Highlevel", () => { }); it("uploadFileToAzureFile should success for samll data", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + await uploadFileToAzureFile(tempFileSmall, fileClient, { parallelism: 20, rangeSize: 4 * 1024 * 1024 }); - const downloadResponse = await fileClient.download(Aborter.none, 0); + const downloadResponse = await fileClient.download(0); const downloadedFile = path.join(tempFolderPath, getUniqueName("downloadfile.")); await readStreamToLocalFile(downloadResponse.readableStreamBody!, downloadedFile); @@ -96,7 +96,8 @@ describe("Highlevel", () => { const aborter = Aborter.timeout(1); try { - await uploadFileToAzureFile(aborter, tempFileLarge, fileClient, { + await uploadFileToAzureFile(tempFileLarge, fileClient, { + abortSignal: aborter, parallelism: 20, rangeSize: 4 * 1024 * 1024 }); @@ -110,7 +111,8 @@ describe("Highlevel", () => { const aborter = Aborter.timeout(1); try { - await uploadFileToAzureFile(aborter, tempFileSmall, fileClient, { + await uploadFileToAzureFile(tempFileSmall, fileClient, { + abortSignal: aborter, parallelism: 20, rangeSize: 4 * 1024 * 1024 }); @@ -125,7 +127,8 @@ describe("Highlevel", () => { const aborter = Aborter.none; try { - await uploadFileToAzureFile(aborter, tempFileLarge, fileClient, { + await uploadFileToAzureFile(tempFileLarge, fileClient, { + abortSignal: aborter, parallelism: 20, progress: (ev) => { assert.ok(ev.loadedBytes); @@ -143,7 +146,8 @@ describe("Highlevel", () => { const aborter = Aborter.none; try { - await uploadFileToAzureFile(aborter, tempFileSmall, fileClient, { + await uploadFileToAzureFile(tempFileSmall, fileClient, { + abortSignal: aborter, parallelism: 20, progress: (ev) => { assert.ok(ev.loadedBytes); @@ -158,16 +162,9 @@ describe("Highlevel", () => { it("uploadStreamToAzureFile should success", async () => { const rs = fs.createReadStream(tempFileLarge); - await uploadStreamToAzureFile( - Aborter.none, - rs, - tempFileLargeLength, - fileClient, - 4 * 1024 * 1024, - 20 - ); + await uploadStreamToAzureFile(rs, tempFileLargeLength, fileClient, 4 * 1024 * 1024, 20); - const downloadResponse = await fileClient.download(Aborter.none, 0); + const downloadResponse = await fileClient.download(0); const downloadFilePath = path.join(tempFolderPath, getUniqueName("downloadFile")); await readStreamToLocalFile(downloadResponse.readableStreamBody!, downloadFilePath); @@ -184,14 +181,9 @@ describe("Highlevel", () => { const aborter = Aborter.timeout(1); try { - await uploadStreamToAzureFile( - aborter, - rs, - tempFileLargeLength, - fileClient, - 4 * 1024 * 1024, - 20 - ); + await uploadStreamToAzureFile(rs, tempFileLargeLength, fileClient, 4 * 1024 * 1024, 20, { + abortSignal: aborter + }); assert.fail(); } catch (err) { assert.ok((err.code as string).toLowerCase().includes("abort")); @@ -202,36 +194,21 @@ describe("Highlevel", () => { const rs = fs.createReadStream(tempFileLarge); let eventTriggered = false; - await uploadStreamToAzureFile( - Aborter.none, - rs, - tempFileLargeLength, - fileClient, - 4 * 1024 * 1024, - 20, - { - progress: (ev) => { - assert.ok(ev.loadedBytes); - eventTriggered = true; - } + await uploadStreamToAzureFile(rs, tempFileLargeLength, fileClient, 4 * 1024 * 1024, 20, { + progress: (ev) => { + assert.ok(ev.loadedBytes); + eventTriggered = true; } - ); + }); assert.ok(eventTriggered); }); it("downloadAzureFileToBuffer should success", async () => { const rs = fs.createReadStream(tempFileLarge); - await uploadStreamToAzureFile( - Aborter.none, - rs, - tempFileLargeLength, - fileClient, - 4 * 1024 * 1024, - 20 - ); + await uploadStreamToAzureFile(rs, tempFileLargeLength, fileClient, 4 * 1024 * 1024, 20); const buf = Buffer.alloc(tempFileLargeLength); - await downloadAzureFileToBuffer(Aborter.none, buf, fileClient, 0, undefined, { + await downloadAzureFileToBuffer(buf, fileClient, 0, undefined, { parallelism: 20, rangeSize: 4 * 1024 * 1024 }); @@ -242,18 +219,12 @@ describe("Highlevel", () => { it("downloadAzureFileToBuffer should abort", async () => { const rs = fs.createReadStream(tempFileLarge); - await uploadStreamToAzureFile( - Aborter.none, - rs, - tempFileLargeLength, - fileClient, - 4 * 1024 * 1024, - 20 - ); + await uploadStreamToAzureFile(rs, tempFileLargeLength, fileClient, 4 * 1024 * 1024, 20); try { const buf = Buffer.alloc(tempFileLargeLength); - await downloadAzureFileToBuffer(Aborter.timeout(1), buf, fileClient, 0, undefined, { + await downloadAzureFileToBuffer(buf, fileClient, 0, undefined, { + abortSignal: Aborter.timeout(1), parallelism: 20, rangeSize: 4 * 1024 * 1024 }); @@ -265,20 +236,14 @@ describe("Highlevel", () => { it("downloadAzureFileToBuffer should update progress event", async () => { const rs = fs.createReadStream(tempFileSmall); - await uploadStreamToAzureFile( - Aborter.none, - rs, - tempFileSmallLength, - fileClient, - 4 * 1024 * 1024, - 10 - ); + await uploadStreamToAzureFile(rs, tempFileSmallLength, fileClient, 4 * 1024 * 1024, 10); let eventTriggered = false; const buf = Buffer.alloc(tempFileSmallLength); const aborter = Aborter.none; try { - await downloadAzureFileToBuffer(aborter, buf, fileClient, 0, undefined, { + await downloadAzureFileToBuffer(buf, fileClient, 0, undefined, { + abortSignal: aborter, parallelism: 1, progress: () => { eventTriggered = true; @@ -290,14 +255,14 @@ describe("Highlevel", () => { assert.ok(eventTriggered); }); - it("bloburl.download should success when internal stream unexcepted ends at the stream end", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + it("fileClient.download should success when internal stream unexcepted ends at the stream end", async () => { + await uploadFileToAzureFile(tempFileSmall, fileClient, { rangeSize: 4 * 1024 * 1024, parallelism: 20 }); let retirableReadableStreamOptions: IRetriableReadableStreamOptions; - const downloadResponse = await fileClient.download(Aborter.none, 0, undefined, { + const downloadResponse = await fileClient.download(0, undefined, { maxRetryRequests: 1, progress: (ev) => { if (ev.loadedBytes >= tempFileSmallLength) { @@ -318,15 +283,15 @@ describe("Highlevel", () => { assert.ok(downloadedData.equals(uploadedData)); }); - it("bloburl.download should download full data successfully when internal stream unexcepted ends", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + it("fileClient.download should download full data successfully when internal stream unexcepted ends", async () => { + await uploadFileToAzureFile(tempFileSmall, fileClient, { rangeSize: 4 * 1024 * 1024, parallelism: 20 }); let retirableReadableStreamOptions: IRetriableReadableStreamOptions; let injectedErrors = 0; - const downloadResponse = await fileClient.download(Aborter.none, 0, undefined, { + const downloadResponse = await fileClient.download(0, undefined, { maxRetryRequests: 3, progress: () => { if (injectedErrors++ < 3) { @@ -347,8 +312,8 @@ describe("Highlevel", () => { assert.ok(downloadedData.equals(uploadedData)); }); - it("bloburl.download should download partial data when internal stream unexcepted ends", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + it("fileClient.download should download partial data when internal stream unexcepted ends", async () => { + await uploadFileToAzureFile(tempFileSmall, fileClient, { rangeSize: 4 * 1024 * 1024, parallelism: 20 }); @@ -357,7 +322,7 @@ describe("Highlevel", () => { let retirableReadableStreamOptions: IRetriableReadableStreamOptions; let injectedErrors = 0; - const downloadResponse = await fileClient.download(Aborter.none, 1, partialSize, { + const downloadResponse = await fileClient.download(1, partialSize, { maxRetryRequests: 3, progress: () => { if (injectedErrors++ < 3) { @@ -378,8 +343,8 @@ describe("Highlevel", () => { assert.ok(downloadedData.equals(uploadedData.slice(1, partialSize + 1))); }); - it("bloburl.download should download data failed when exceeding max stream retry requests", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + it("fileClient.download should download data failed when exceeding max stream retry requests", async () => { + await uploadFileToAzureFile(tempFileSmall, fileClient, { rangeSize: 4 * 1024 * 1024, parallelism: 20 }); @@ -391,7 +356,7 @@ describe("Highlevel", () => { let expectedError = false; try { - const downloadResponse = await fileClient.download(Aborter.none, 0, undefined, { + const downloadResponse = await fileClient.download(0, undefined, { maxRetryRequests: 0, progress: () => { if (injectedErrors++ < 1) { @@ -409,8 +374,8 @@ describe("Highlevel", () => { fs.unlinkSync(downloadedFile); }); - it("bloburl.download should abort after retrys", async () => { - await uploadFileToAzureFile(Aborter.none, tempFileSmall, fileClient, { + it("fileClient.download should abort after retrys", async () => { + await uploadFileToAzureFile(tempFileSmall, fileClient, { rangeSize: 4 * 1024 * 1024, parallelism: 20 }); @@ -423,7 +388,8 @@ describe("Highlevel", () => { try { const aborter = Aborter.none; - const downloadResponse = await fileClient.download(aborter, 0, undefined, { + const downloadResponse = await fileClient.download(0, undefined, { + abortSignal: aborter, maxRetryRequests: 3, progress: () => { if (injectedErrors++ < 2) { diff --git a/sdk/storage/storage-file/test/node/sas.spec.ts b/sdk/storage/storage-file/test/node/sas.spec.ts index ab17eecabea6..351587c5155e 100644 --- a/sdk/storage/storage-file/test/node/sas.spec.ts +++ b/sdk/storage/storage-file/test/node/sas.spec.ts @@ -11,7 +11,6 @@ import { StorageClient, SASProtocol } from "../../src"; -import { Aborter } from "../../src/Aborter"; import { DirectoryClient } from "../../src/DirectoryClient"; import { FileSASPermissions } from "../../src/FileSASPermissions"; import { FileClient } from "../../src/FileClient"; @@ -54,7 +53,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageClient.newPipeline(new AnonymousCredential()) ); - await serviceClientWithSAS.listSharesSegment(Aborter.none); + await serviceClientWithSAS.listSharesSegment(); }); it("generateAccountSASQueryParameters should not work with invalid permission", async () => { @@ -83,7 +82,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceClientWithSAS.getProperties(Aborter.none); + await serviceClientWithSAS.getProperties(); } catch (err) { error = err; } @@ -117,7 +116,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceClientWithSAS.getProperties(Aborter.none); + await serviceClientWithSAS.getProperties(); } catch (err) { error = err; } @@ -154,7 +153,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { let error; try { - await serviceClientWithSAS.getProperties(Aborter.none); + await serviceClientWithSAS.getProperties(); } catch (err) { error = err; } @@ -175,7 +174,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const shareName = getUniqueName("share"); const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); const shareSAS = generateFileSASQueryParameters( { @@ -197,9 +196,9 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { ); const dirURLwithSAS = DirectoryClient.fromShareClient(shareClientwithSAS, ""); - await dirURLwithSAS.listFilesAndDirectoriesSegment(Aborter.none); + await dirURLwithSAS.listFilesAndDirectoriesSegment(); - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("generateFileSASQueryParameters should work for file", async () => { @@ -215,15 +214,15 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const shareName = getUniqueName("share"); const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); const dirName = getUniqueName("dir"); const dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); const fileName = getUniqueName("file"); const fileClient = FileClient.fromDirectoryClient(dirClient, fileName); - await fileClient.create(Aborter.none, 1024, { + await fileClient.create(1024, { fileHTTPHeaders: { fileContentType: "content-type-original" } @@ -254,14 +253,14 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { StorageClient.newPipeline(new AnonymousCredential()) ); - const properties = await fileClientwithSAS.getProperties(Aborter.none); + const properties = await fileClientwithSAS.getProperties(); assert.equal(properties.cacheControl, "cache-control-override"); assert.equal(properties.contentDisposition, "content-disposition-override"); assert.equal(properties.contentEncoding, "content-encoding-override"); assert.equal(properties.contentLanguage, "content-language-override"); assert.equal(properties.contentType, "content-type-override"); - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("generateFileSASQueryParameters should work for file with access policy", async () => { @@ -277,22 +276,22 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { const shareName = getUniqueName("share"); const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); const dirName = getUniqueName("dir"); const dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); const fileName = getUniqueName("file"); const fileClient = FileClient.fromDirectoryClient(dirClient, fileName); - await fileClient.create(Aborter.none, 1024, { + await fileClient.create(1024, { fileHTTPHeaders: { fileContentType: "content-type-original" } }); const id = "unique-id"; - await shareClient.setAccessPolicy(Aborter.none, [ + await shareClient.setAccessPolicy([ { accessPolicy: { expiry: tmr, @@ -318,7 +317,7 @@ describe("Shared Access Signature (SAS) generation Node.js only", () => { ); const dirURLwithSAS = DirectoryClient.fromShareClient(shareClientwithSAS, ""); - await dirURLwithSAS.listFilesAndDirectoriesSegment(Aborter.none); - await shareClient.delete(Aborter.none); + await dirURLwithSAS.listFilesAndDirectoriesSegment(); + await shareClient.delete(); }); }); diff --git a/sdk/storage/storage-file/test/node/shareclient.spec.ts b/sdk/storage/storage-file/test/node/shareclient.spec.ts index 96e8c6ea5cbc..5ae036061f34 100644 --- a/sdk/storage/storage-file/test/node/shareclient.spec.ts +++ b/sdk/storage/storage-file/test/node/shareclient.spec.ts @@ -1,6 +1,4 @@ import * as assert from "assert"; - -import { Aborter } from "../../src/Aborter"; import { ISignedIdentifier, ShareClient } from "../../src/ShareClient"; import { getBSU, getUniqueName } from "./../utils"; @@ -12,11 +10,11 @@ describe("ShareClient", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("setAccessPolicy", async () => { @@ -36,8 +34,8 @@ describe("ShareClient", () => { } ]; - await shareClient.setAccessPolicy(Aborter.none, identifiers); - const getAccessPolicyResponse = await shareClient.getAccessPolicy(Aborter.none); + await shareClient.setAccessPolicy(identifiers); + const getAccessPolicyResponse = await shareClient.getAccessPolicy(); assert.equal(getAccessPolicyResponse.signedIdentifiers[0].id, identifiers[0].id); assert.equal( diff --git a/sdk/storage/storage-file/test/node/sharedkeycredentialpolicy.spec.ts b/sdk/storage/storage-file/test/node/sharedkeycredentialpolicy.spec.ts index 85a74970e31f..860a0d99acaf 100644 --- a/sdk/storage/storage-file/test/node/sharedkeycredentialpolicy.spec.ts +++ b/sdk/storage/storage-file/test/node/sharedkeycredentialpolicy.spec.ts @@ -1,4 +1,3 @@ -import { Aborter } from "../../src/Aborter"; import { DirectoryClient } from "../../src/DirectoryClient"; import { FileClient } from "../../src/FileClient"; import { ShareClient } from "../../src/ShareClient"; @@ -10,30 +9,30 @@ describe("SharedKeyCredentialPolicy Node.js only", () => { const shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); before(async () => { - await shareClient.create(Aborter.none); + await shareClient.create(); }); after(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("SharedKeyCredentialPolicy should work with special share and file names with spaces", async () => { const dirName = getUniqueName("dir empty"); const dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); const fileName: string = getUniqueName("file empty"); const fileClient = FileClient.fromDirectoryClient(dirClient, fileName); - await fileClient.create(Aborter.none, 0); + await fileClient.create(0); }); it("SharedKeyCredentialPolicy should work with special share and file names uppercase", async () => { const dirName = getUniqueName("Dir empty"); const dirClient = DirectoryClient.fromShareClient(shareClient, dirName); - await dirClient.create(Aborter.none); + await dirClient.create(); const fileName: string = getUniqueName("Upper_another"); const fileClient = FileClient.fromDirectoryClient(dirClient, fileName); - await fileClient.create(Aborter.none, 0); + await fileClient.create(0); }); }); diff --git a/sdk/storage/storage-file/test/retrypolicy.spec.ts b/sdk/storage/storage-file/test/retrypolicy.spec.ts index 99704922b7d7..35347c270f67 100644 --- a/sdk/storage/storage-file/test/retrypolicy.spec.ts +++ b/sdk/storage/storage-file/test/retrypolicy.spec.ts @@ -1,7 +1,5 @@ import * as assert from "assert"; - import { RestError, StorageClient } from "../src"; -import { Aborter } from "../src/Aborter"; import { ShareClient } from "../src/ShareClient"; import { Pipeline } from "../src/Pipeline"; import { getBSU, getUniqueName } from "./utils"; @@ -17,11 +15,11 @@ describe("RetryPolicy", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("Retry Policy should work when first request fails with 500", async () => { @@ -42,9 +40,9 @@ describe("RetryPolicy", () => { keya: "vala", keyb: "valb" }; - await injectShareClient.setMetadata(Aborter.none, metadata); + await injectShareClient.setMetadata(metadata); - const result = await shareClient.getProperties(Aborter.none); + const result = await shareClient.getProperties(); assert.deepEqual(result.metadata, metadata); }); @@ -68,7 +66,7 @@ describe("RetryPolicy", () => { keya: "vala", keyb: "valb" }; - await injectShareClient.setMetadata(Aborter.none, metadata); + await injectShareClient.setMetadata(metadata); } catch (err) { hasError = true; } diff --git a/sdk/storage/storage-file/test/shareclient.spec.ts b/sdk/storage/storage-file/test/shareclient.spec.ts index 84d567d3f0eb..00ddc50fab25 100644 --- a/sdk/storage/storage-file/test/shareclient.spec.ts +++ b/sdk/storage/storage-file/test/shareclient.spec.ts @@ -1,6 +1,4 @@ import * as assert from "assert"; - -import { Aborter } from "../src/Aborter"; import { ShareClient } from "../src/ShareClient"; import { getBSU, getUniqueName } from "./utils"; import * as dotenv from "dotenv"; @@ -14,11 +12,11 @@ describe("ShareClient", () => { beforeEach(async () => { shareName = getUniqueName("share"); shareClient = ShareClient.fromFileServiceClient(serviceClient, shareName); - await shareClient.create(Aborter.none); + await shareClient.create(); }); afterEach(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("setMetadata", async () => { @@ -27,14 +25,14 @@ describe("ShareClient", () => { keya: "vala", keyb: "valb" }; - await shareClient.setMetadata(Aborter.none, metadata); + await shareClient.setMetadata(metadata); - const result = await shareClient.getProperties(Aborter.none); + const result = await shareClient.getProperties(); assert.deepEqual(result.metadata, metadata); }); it("getProperties", async () => { - const result = await shareClient.getProperties(Aborter.none); + const result = await shareClient.getProperties(); assert.ok(result.eTag!.length > 0); assert.ok(result.lastModified); assert.ok(result.requestId); @@ -50,8 +48,8 @@ describe("ShareClient", () => { it("create with all parameters configured", async () => { const shareClient2 = ShareClient.fromFileServiceClient(serviceClient, getUniqueName(shareName)); const metadata = { key: "value" }; - await shareClient2.create(Aborter.none, { metadata }); - const result = await shareClient2.getProperties(Aborter.none); + await shareClient2.create({ metadata }); + const result = await shareClient2.getProperties(); assert.deepEqual(result.metadata, metadata); }); @@ -62,19 +60,19 @@ describe("ShareClient", () => { it("setQuota", async () => { const quotaInGB = 20; - await shareClient.setQuota(Aborter.none, quotaInGB); - const propertiesResponse = await shareClient.getProperties(Aborter.none); + await shareClient.setQuota(quotaInGB); + const propertiesResponse = await shareClient.getProperties(); assert.equal(propertiesResponse.quota, quotaInGB); }); it("getStatistics", async () => { - const statisticsResponse = await shareClient.getStatistics(Aborter.none); + const statisticsResponse = await shareClient.getStatistics(); assert.notEqual(statisticsResponse.shareUsage, undefined); }); it("create snapshot", async () => { const metadata = { key1: "value1", key2: "value2" }; - const createSnapshotResponse = await shareClient.createSnapshot(Aborter.none, { + const createSnapshotResponse = await shareClient.createSnapshot({ metadata }); @@ -82,12 +80,12 @@ describe("ShareClient", () => { const sanpshot = createSnapshotResponse.snapshot!; const snapshotShareClient = shareClient.withSnapshot(sanpshot); - const snapshotProperties = await snapshotShareClient.getProperties(Aborter.none); + const snapshotProperties = await snapshotShareClient.getProperties(); assert.deepStrictEqual(snapshotProperties.metadata, metadata); - const originProperties = await shareClient.getProperties(Aborter.none); + const originProperties = await shareClient.getProperties(); assert.notDeepStrictEqual(originProperties.metadata, metadata); - await snapshotShareClient.delete(Aborter.none, {}); + await snapshotShareClient.delete({}); }); }); diff --git a/sdk/storage/storage-file/test/specialnaming.spec.ts b/sdk/storage/storage-file/test/specialnaming.spec.ts index f1d89eb447ad..e586f8822cc3 100644 --- a/sdk/storage/storage-file/test/specialnaming.spec.ts +++ b/sdk/storage/storage-file/test/specialnaming.spec.ts @@ -1,4 +1,3 @@ -import { Aborter } from "../src/Aborter"; import { FileClient } from "../src/FileClient"; import { ShareClient } from "../src/ShareClient"; import { getBSU, getUniqueName } from "./utils/index"; @@ -16,20 +15,20 @@ describe("Special Naming Tests", () => { const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName); before(async () => { - await shareClient.create(Aborter.none); - await directoryClient.create(Aborter.none); + await shareClient.create(); + await directoryClient.create(); }); after(async () => { - await shareClient.delete(Aborter.none); + await shareClient.delete(); }); it("Should work with special container and file names with spaces", async () => { const fileName: string = getUniqueName("file empty"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -42,8 +41,8 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -53,9 +52,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("Upper file empty another"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -68,9 +67,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -80,9 +79,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("Upper file empty another 汉字"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -95,9 +94,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -107,9 +106,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("汉字. special ~!@#$%^&()_+`1234567890-={}[];','"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { // NOTICE: Azure Storage Server will replace "\" with "/" in the file names prefix: fileName.replace(/\\/g, "/") }); @@ -126,9 +125,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { // NOTICE: Azure Storage Server will replace "\" with "/" in the file names prefix: fileName.replace(/\\/g, "/") }); @@ -140,16 +139,12 @@ describe("Special Naming Tests", () => { const specialDirectoryClient = DirectoryClient.fromShareClient(shareClient, directoryName); const rootDirectoryClient = DirectoryClient.fromShareClient(shareClient, ""); - await specialDirectoryClient.create(Aborter.none); - await specialDirectoryClient.getProperties(Aborter.none); - const response = await rootDirectoryClient.listFilesAndDirectoriesSegment( - Aborter.none, - undefined, - { - // NOTICE: Azure Storage Server will replace "\" with "/" in the file names - prefix: directoryName.replace(/\\/g, "/") - } - ); + await specialDirectoryClient.create(); + await specialDirectoryClient.getProperties(); + const response = await rootDirectoryClient.listFilesAndDirectoriesSegment(undefined, { + // NOTICE: Azure Storage Server will replace "\" with "/" in the file names + prefix: directoryName.replace(/\\/g, "/") + }); assert.notDeepEqual(response.segment.directoryItems.length, 0); }); @@ -163,18 +158,14 @@ describe("Special Naming Tests", () => { shareClient.pipeline ); - await specialDirectoryClient.create(Aborter.none); - await specialDirectoryClient.getProperties(Aborter.none); + await specialDirectoryClient.create(); + await specialDirectoryClient.getProperties(); const rootDirectoryClient = DirectoryClient.fromShareClient(shareClient, ""); - const response = await rootDirectoryClient.listFilesAndDirectoriesSegment( - Aborter.none, - undefined, - { - // NOTICE: Azure Storage Server will replace "\" with "/" in the file names - prefix: directoryName.replace(/\\/g, "/") - } - ); + const response = await rootDirectoryClient.listFilesAndDirectoriesSegment(undefined, { + // NOTICE: Azure Storage Server will replace "\" with "/" in the file names + prefix: directoryName.replace(/\\/g, "/") + }); assert.notDeepEqual(response.segment.directoryItems.length, 0); }); @@ -183,9 +174,9 @@ describe("Special Naming Tests", () => { const blobNameEncoded: string = encodeURIComponent(fileName); const fileClient = FileClient.fromDirectoryClient(directoryClient, blobNameEncoded); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: blobNameEncoded }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -195,9 +186,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("ру́сский язы́к"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -210,9 +201,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -223,9 +214,9 @@ describe("Special Naming Tests", () => { const blobNameEncoded: string = encodeURIComponent(fileName); const fileClient = FileClient.fromDirectoryClient(directoryClient, blobNameEncoded); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: blobNameEncoded }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -235,9 +226,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("عربيعربى"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -250,9 +241,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -263,9 +254,9 @@ describe("Special Naming Tests", () => { const blobNameEncoded: string = encodeURIComponent(fileName); const fileClient = FileClient.fromDirectoryClient(directoryClient, blobNameEncoded); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: blobNameEncoded }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -275,9 +266,9 @@ describe("Special Naming Tests", () => { const fileName: string = getUniqueName("にっぽんごにほんご"); const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0); @@ -290,9 +281,9 @@ describe("Special Naming Tests", () => { directoryClient.pipeline ); - await fileClient.create(Aborter.none, 10); - await fileClient.getProperties(Aborter.none); - const response = await directoryClient.listFilesAndDirectoriesSegment(Aborter.none, undefined, { + await fileClient.create(10); + await fileClient.getProperties(); + const response = await directoryClient.listFilesAndDirectoriesSegment(undefined, { prefix: fileName }); assert.notDeepEqual(response.segment.fileItems.length, 0);