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

[Storage-file] Rename *URL to *Client #2877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions sdk/storage/storage-file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ For example, you can create following CORS settings for debugging. But please cu

The Azure Storage SDK for JavaScript provides low-level and high-level APIs.

* ServiceURL, ShareURL, DirectoryURL and FileURL objects provide the low-level API functionality and map one-to-one to the [Azure Storage File REST APIs](https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api).
* FileServiceClient, ShareClient, DirectoryClient and FileClient objects provide the low-level API functionality and map one-to-one to the [Azure Storage File REST APIs](https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api).

* The high-level APIs provide convenience abstractions such as uploading a large stream to a file (using multiple PutBlock requests).

Expand All @@ -125,11 +125,11 @@ The Azure Storage SDK for JavaScript provides low-level and high-level APIs.
```javascript
const {
Aborter,
StorageURL,
ServiceURL,
ShareURL,
DirectoryURL,
FileURL,
StorageClient,
FileServiceClient,
ShareClient,
DirectoryClient,
FileClient,
SharedKeyCredential,
AnonymousCredential
} = require("@azure/storage-file");
Expand All @@ -147,10 +147,10 @@ async function main() {
const anonymousCredential = new AnonymousCredential();

// Use sharedKeyCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
const pipeline = StorageClient.newPipeline(sharedKeyCredential);

// List shares
const serviceURL = new ServiceURL(
const servieClient = new FileServiceClient(
// When using AnonymousCredential, following url should include a valid SAS
`https://${account}.file.core.windows.net`,
pipeline
Expand All @@ -159,7 +159,7 @@ async function main() {
console.log(`List shares`);
let marker;
do {
const listSharesResponse = await serviceURL.listSharesSegment(
const listSharesResponse = await servieClient.listSharesSegment(
Aborter.none,
marker
);
Expand All @@ -172,32 +172,32 @@ async function main() {

// Create a share
const shareName = `newshare${new Date().getTime()}`;
const shareURL = ShareURL.fromServiceURL(serviceURL, shareName);
await shareURL.create(Aborter.none);
const shareClient = ShareClient.fromFileServiceClient(servieClient, shareName);
await shareClient.create(Aborter.none);
console.log(`Create share ${shareName} successfully`);

// Create a directory
const directoryName = `newdirectory${new Date().getTime()}`;
const directoryURL = DirectoryURL.fromShareURL(shareURL, directoryName);
await directoryURL.create(Aborter.none);
const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName);
await directoryClient.create(Aborter.none);
console.log(`Create directory ${directoryName} successfully`);

// Create a file
const content = "Hello World!";
const fileName = "newfile" + new Date().getTime();
const fileURL = FileURL.fromDirectoryURL(directoryURL, fileName);
await fileURL.create(Aborter.none, content.length);
const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName);
await fileClient.create(Aborter.none, content.length);
console.log(`Create file ${fileName} successfully`);

// Upload file range
await fileURL.uploadRange(Aborter.none, content, 0, content.length);
await fileClient.uploadRange(Aborter.none, content, 0, content.length);
console.log(`Upload file range "${content}" to ${fileName} successfully`);

// List directories and files
console.log(`List directories and files under directory ${directoryName}`);
marker = undefined;
do {
const listFilesAndDirectoriesResponse = await directoryURL.listFilesAndDirectoriesSegment(
const listFilesAndDirectoriesResponse = await directoryClient.listFilesAndDirectoriesSegment(
Aborter.none,
marker
);
Expand All @@ -215,15 +215,15 @@ 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 fileURL.download(Aborter.none, 0);
const downloadFileResponse = await fileClient.download(Aborter.none, 0);
console.log(
`Downloaded file content${await streamToString(
downloadFileResponse.readableStreamBody
)}`
);

// Delete share
await shareURL.delete(Aborter.none);
await shareClient.delete(Aborter.none);
console.log(`deleted share ${shareName}`);
}

Expand Down
34 changes: 17 additions & 17 deletions sdk/storage/storage-file/samples/javascript/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const {
uploadFileToAzureFile,
uploadStreamToAzureFile,
Aborter,
FileURL,
DirectoryURL,
ShareURL,
ServiceURL,
StorageURL
FileClient,
DirectoryClient,
ShareClient,
FileServiceClient,
StorageClient
} = require(".."); // Change to "@azure/storage-file" in your package

async function main() {
Expand All @@ -23,38 +23,38 @@ async function main() {
const accountSas = "";
const localFilePath = "";

const pipeline = StorageURL.newPipeline(new AnonymousCredential(), {
const pipeline = StorageClient.newPipeline(new AnonymousCredential(), {
// httpClient: MyHTTPClient, // A customized HTTP client implementing IHttpClient interface
// logger: MyLogger, // A customized logger implementing IHttpPipelineLogger interface
retryOptions: { maxTries: 4 }, // Retry options
telemetry: { value: "HighLevelSample V1.0.0" } // Customized telemetry string
});

const serviceURL = new ServiceURL(
const servieClient = new FileServiceClient(
`https://${account}.file.core.windows.net${accountSas}`,
pipeline
);

// Create a share
const shareName = `newshare${new Date().getTime()}`;
const shareURL = ShareURL.fromServiceURL(serviceURL, shareName);
await shareURL.create(Aborter.none);
const shareClient = ShareClient.fromFileServiceClient(servieClient, shareName);
await shareClient.create(Aborter.none);
console.log(`Create share ${shareName} successfully`);

// Create a directory
const directoryName = `newdirectory${new Date().getTime()}`;
const directoryURL = DirectoryURL.fromShareURL(shareURL, directoryName);
await directoryURL.create(Aborter.none);
const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName);
await directoryClient.create(Aborter.none);
console.log(`Create directory ${directoryName} successfully`);

// Upload local file to Azure file parallelly
const fileName = "newfile" + new Date().getTime();
const fileURL = FileURL.fromDirectoryURL(directoryURL, fileName);
const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName);
const fileSize = fs.statSync(localFilePath).size;

// Parallel uploading with uploadFileToAzureFile in Node.js runtime
// uploadFileToAzureFile is only available in Node.js
await uploadFileToAzureFile(Aborter.none, localFilePath, fileURL, {
await uploadFileToAzureFile(Aborter.none, localFilePath, fileClient, {
rangeSize: 4 * 1024 * 1024, // 4MB range size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -67,7 +67,7 @@ async function main() {
Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
fs.createReadStream(localFilePath),
fileSize,
fileURL,
fileClient,
4 * 1024 * 1024,
20,
{
Expand All @@ -80,7 +80,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, fileURL, {
await uploadBrowserDataToAzureFile(Aborter.none, browserFile, fileClient, {
rangeSize: 4 * 1024 * 1024, // 4MB range size
parallelism: 20, // 20 concurrency
progress: ev => console.log(ev)
Expand All @@ -93,7 +93,7 @@ async function main() {
await downloadAzureFileToBuffer(
Aborter.timeout(30 * 60 * 1000),
buffer,
fileURL,
fileClient,
0,
undefined,
{
Expand All @@ -105,7 +105,7 @@ async function main() {
console.log("downloadAzureFileToBuffer success");

// Delete share
await shareURL.delete(Aborter.none);
await shareClient.delete(Aborter.none);
console.log("deleted share");
}

Expand Down
36 changes: 18 additions & 18 deletions sdk/storage/storage-file/samples/javascript/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

const {
Aborter,
StorageURL,
ServiceURL,
ShareURL,
DirectoryURL,
FileURL,
StorageClient,
FileServiceClient,
ShareClient,
DirectoryClient,
FileClient,
SharedKeyCredential,
AnonymousCredential
} = require(".."); // Change to "@azure/storage-file" in your package
Expand All @@ -26,10 +26,10 @@ async function main() {
const anonymousCredential = new AnonymousCredential();

// Use sharedKeyCredential or anonymousCredential to create a pipeline
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
const pipeline = StorageClient.newPipeline(sharedKeyCredential);

// List shares
const serviceURL = new ServiceURL(
const servieClient = new FileServiceClient(
// When using AnonymousCredential, following url should include a valid SAS
`https://${account}.file.core.windows.net`,
pipeline
Expand All @@ -38,7 +38,7 @@ async function main() {
console.log(`List shares`);
let marker;
do {
const listSharesResponse = await serviceURL.listSharesSegment(
const listSharesResponse = await servieClient.listSharesSegment(
Aborter.none,
marker
);
Expand All @@ -51,32 +51,32 @@ async function main() {

// Create a share
const shareName = `newshare${new Date().getTime()}`;
const shareURL = ShareURL.fromServiceURL(serviceURL, shareName);
await shareURL.create(Aborter.none);
const shareClient = ShareClient.fromFileServiceClient(servieClient, shareName);
await shareClient.create(Aborter.none);
console.log(`Create share ${shareName} successfully`);

// Create a directory
const directoryName = `newdirectory${new Date().getTime()}`;
const directoryURL = DirectoryURL.fromShareURL(shareURL, directoryName);
await directoryURL.create(Aborter.none);
const directoryClient = DirectoryClient.fromShareClient(shareClient, directoryName);
await directoryClient.create(Aborter.none);
console.log(`Create directory ${directoryName} successfully`);

// Create a file
const content = "Hello World!";
const fileName = "newfile" + new Date().getTime();
const fileURL = FileURL.fromDirectoryURL(directoryURL, fileName);
await fileURL.create(Aborter.none, content.length);
const fileClient = FileClient.fromDirectoryClient(directoryClient, fileName);
await fileClient.create(Aborter.none, content.length);
console.log(`Create file ${fileName} successfully`);

// Upload file range
await fileURL.uploadRange(Aborter.none, content, 0, content.length);
await fileClient.uploadRange(Aborter.none, content, 0, content.length);
console.log(`Upload file range "${content}" to ${fileName} successfully`);

// List directories and files
console.log(`List directories and files under directory ${directoryName}`);
marker = undefined;
do {
const listFilesAndDirectoriesResponse = await directoryURL.listFilesAndDirectoriesSegment(
const listFilesAndDirectoriesResponse = await directoryClient.listFilesAndDirectoriesSegment(
Aborter.none,
marker
);
Expand All @@ -94,15 +94,15 @@ 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 fileURL.download(Aborter.none, 0);
const downloadFileResponse = await fileClient.download(Aborter.none, 0);
console.log(
`Downloaded file content${await streamToString(
downloadFileResponse.readableStreamBody
)}`
);

// Delete share
await shareURL.delete(Aborter.none);
await shareClient.delete(Aborter.none);
console.log(`deleted share ${shareName}`);
}

Expand Down
Loading