Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ⬆️ to newest Azure Storage SDK for blobs 🗄 #513

Merged
merged 18 commits into from
Dec 4, 2019
2,594 changes: 1,008 additions & 1,586 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@
"ms-vscode.azure-account"
],
"dependencies": {
"@azure/storage-blob": "^12.0.0",
"@types/mime": "^2.0.1",
"azure-arm-resource": "^3.1.1-preview",
"azure-arm-storage": "^5.1.1-preview",
Expand Down
46 changes: 29 additions & 17 deletions src/azureStorageExplorer/AzureStorageFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { BlobClient, BlobDownloadResponseModel } from "@azure/storage-blob";
import * as azureStorage from "azure-storage";
import * as path from "path";
import * as querystring from "querystring";
import * as vscode from "vscode";
import { AzExtTreeItem, callWithTelemetryAndErrorHandling, IActionContext, parseError } from "vscode-azureextensionui";
import { ext } from "../extensionVariables";
import { BlobContainerTreeItem, IBlobContainerCreateChildContext } from "./blobContainers/blobContainerNode";
import { BlobDirectoryTreeItem } from "./blobContainers/BlobDirectoryTreeItem";
import { BlobContainerTreeItem } from "./blobContainers/blobContainerNode";
import { BlobDirectoryTreeItem } from "./blobContainers/blobDirectoryNode";
import { BlobTreeItem } from "./blobContainers/blobNode";
import { createBlobClient, createBlockBlob, doesBlobExist, IBlobContainerCreateChildContext } from './blobContainers/blobUtils';
import { DirectoryTreeItem, IDirectoryDeleteContext } from "./fileShares/directoryNode";
import { FileTreeItem } from "./fileShares/fileNode";
import { FileShareTreeItem, IFileShareCreateChildContext } from "./fileShares/fileShareNode";
Expand Down Expand Up @@ -149,17 +151,9 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
});
});
} else {
let service: azureStorage.BlobService = treeItem.root.createBlobService();
let containerName: string = treeItem.container.name;
result = await new Promise<string | undefined>((resolve, reject) => {
service.getBlobToText(containerName, parsedUri.filePath, (error?: Error, text?: string) => {
if (!!error) {
reject(error);
} else {
resolve(text);
}
});
});
const blobClient: BlobClient = createBlobClient(treeItem.root, treeItem.container.name, parsedUri.filePath);
let downloaded: BlobDownloadResponseModel = await blobClient.download();
result = await this.streamToString(downloaded.readableStreamBody);
}
} catch (error) {
let pe = parseError(error);
Expand Down Expand Up @@ -189,7 +183,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
if (treeItem instanceof FileShareTreeItem) {
childExists = await doesFileExist(parsedUri.baseName, treeItem, parsedUri.parentDirPath, treeItem.share);
} else {
childExists = await treeItem.doesBlobExist(parsedUri.filePath);
childExists = await doesBlobExist(treeItem, parsedUri.filePath);
}

if (!childExists && !options.create) {
Expand All @@ -204,7 +198,8 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
if (treeItem instanceof FileShareTreeItem) {
await updateFileFromText(parsedUri.parentDirPath, parsedUri.baseName, treeItem.share, treeItem.root, content.toString());
} else {
await treeItem.updateBlockBlobFromText(parsedUri.filePath, content.toString());
await createBlockBlob(treeItem, parsedUri.filePath, content.toString());

}
} else {
progress.report({ message: `Creating ${writeToFileShare ? 'file' : 'blob'} ${parsedUri.filePath}` });
Expand Down Expand Up @@ -240,7 +235,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
await vscode.window.withProgress({ location: vscode.ProgressLocation.Notification }, async (progress) => {
if (treeItem instanceof FileTreeItem || treeItem instanceof DirectoryTreeItem || treeItem instanceof BlobTreeItem || treeItem instanceof BlobDirectoryTreeItem) {
if (!(treeItem instanceof BlobDirectoryTreeItem)) {
// The deletion message from deleteTreeItem is not supressed for BlobDirectoryTreeItems so avoid duplicate notifications
// The deletion message from deleteTreeItem is not suppressed for BlobDirectoryTreeItems so avoid duplicate notifications
progress.report({ message: `Deleting ${parsedUri.filePath}` });
}

Expand All @@ -259,7 +254,7 @@ export class AzureStorageFS implements vscode.FileSystemProvider {

context.errorHandling.rethrow = true;
if (oldUriParsed.baseName === newUriParsed.baseName) {
// Set suppressDisplay true when trying to move the files because VS code will hanlde the error.
// Set suppressDisplay true when trying to move the files because VS code will handle the error.
context.errorHandling.suppressDisplay = true;
throw new Error('Moving folders or files not supported.');
} else {
Expand Down Expand Up @@ -408,6 +403,23 @@ export class AzureStorageFS implements vscode.FileSystemProvider {
private isFileShareUri(uri: vscode.Uri): boolean {
return this.verifyUri(uri).query.indexOf('File Shares') > 0;
}

private async streamToString(readableStream: NodeJS.ReadableStream | undefined): Promise<string | undefined> {
if (!readableStream) {
return undefined;
}
return new Promise((resolve, reject) => {
const chunks: string[] = [];
readableStream.on("data", (data) => {
// tslint:disable-next-line: no-unsafe-any
chunks.push(data.toString());
});
readableStream.on("end", () => {
resolve(chunks.join(""));
});
readableStream.on("error", reject);
});
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/azureStorageExplorer/IStorageRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as azureStorageBlob from "@azure/storage-blob";
import * as azureStorage from "azure-storage";
import { ISubscriptionContext } from "vscode-azureextensionui";
import { StorageAccountWrapper } from "../components/storageWrappers";

export interface IStorageRoot extends ISubscriptionContext {
storageAccount: StorageAccountWrapper;
createBlobService(): azureStorage.BlobService;
createBlobServiceClient(): azureStorageBlob.BlobServiceClient;
createFileService(): azureStorage.FileService;
createQueueService(): azureStorage.QueueService;
createTableService(): azureStorage.TableService;
Expand Down
218 changes: 0 additions & 218 deletions src/azureStorageExplorer/blobContainers/BlobDirectoryTreeItem.ts

This file was deleted.

Loading