Bagikan melalui


DataLakeFileClient class

DataLakeFileClient mewakili URL ke file Azure Storage.

Memperluas

Konstruktor

DataLakeFileClient(string, Pipeline)

Membuat instans DataLakeFileClient dari url dan alur.

DataLakeFileClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

Membuat instans DataLakeFileClient dari url dan kredensial.

Properti

fileSystemName

Nama sistem file saat ini.

name

Nama jalur saat ini (direktori atau file).

Properti yang Diwariskan

accountName
credential

Seperti AnonymousCredential, StorageSharedKeyCredential atau kredensial apa pun dari paket @azure/identity untuk mengautentikasi permintaan ke layanan. Anda juga dapat menyediakan objek yang mengimplementasikan antarmuka TokenCredential. Jika tidak ditentukan, AnonymousCredential digunakan.

url

Nilai string URL yang dikodekan.

Metode

append(RequestBodyType, number, number, FileAppendOptions)

Mengunggah data yang akan ditambahkan ke file. Data hanya dapat ditambahkan ke file. Untuk menerapkan data yang diunggah secara pervious ke file, panggil flush.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

create(FileCreateOptions)

Buat file.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

create(PathResourceType, PathCreateOptions)

Buat file.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

createIfNotExists(FileCreateIfNotExistsOptions)

Buat file jika belum ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

createIfNotExists(PathResourceType, PathCreateIfNotExistsOptions)

Buat file jika belum ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

flush(number, FileFlushOptions)

Menghapus (menulis) data yang sebelumnya ditambahkan ke file.

generateSasStringToSign(FileGenerateSasUrlOptions)

Hanya tersedia untuk klien yang dibangun dengan kredensial kunci bersama.

Menghasilkan string untuk masuk ke URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

generateSasUrl(FileGenerateSasUrlOptions)

Hanya tersedia untuk klien yang dibangun dengan kredensial kunci bersama.

Menghasilkan URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

generateUserDelegationSasStringToSign(FileGenerateSasUrlOptions, UserDelegationKey)

Menghasilkan string untuk masuk ke URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kunci delegasi pengguna input.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

generateUserDelegationSasUrl(FileGenerateSasUrlOptions, UserDelegationKey)

Menghasilkan URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kunci delegasi pengguna input.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

query(string, FileQueryOptions)

Kueri cepat untuk file berformat JSON atau CSV.

Contoh penggunaan (Node.js):

import { DataLakeServiceClient } from "@azure/storage-file-datalake";

const account = "<account>";
const sas = "<sas token>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net${sas}`,
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Query and convert a file to a string
const queryResponse = await fileClient.query("select * from BlobStorage");
if (queryResponse.readableStreamBody) {
  const responseBuffer = await streamToBuffer(queryResponse.readableStreamBody);
  const downloaded = responseBuffer.toString();
  console.log(`Query file content: ${downloaded}`);
}

async function streamToBuffer(readableStream: NodeJS.ReadableStream): Promise<Buffer> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = [];
    readableStream.on("data", (data) => {
      chunks.push(data instanceof Buffer ? data : Buffer.from(data));
    });
    readableStream.on("end", () => {
      resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
  });
}
read(number, number, FileReadOptions)

Mengunduh file dari layanan, termasuk metadata dan propertinya.

  • Di Node.js, data kembali dalam aliran yang dapat dibaca ReadableStreamBody
  • Di browser, data kembali dalam konten yang dijanjikanAsBlob

Lihat https://learn.microsoft.com/rest/api/storageservices/get-blob

  • Contoh penggunaan (Node.js):
import { DataLakeServiceClient } from "@azure/storage-file-datalake";
import { DefaultAzureCredential } from "@azure/identity";

const account = "<account>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net`,
  new DefaultAzureCredential(),
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Get file content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadResponse.readableStreamBody
const downloadResponse = await fileClient.read();
if (downloadResponse.readableStreamBody) {
  const downloaded = await streamToBuffer(downloadResponse.readableStreamBody);
  console.log("Downloaded file content:", downloaded.toString());
}

// [Node.js only] A helper method used to read a Node.js readable stream into a Buffer.
async function streamToBuffer(readableStream: NodeJS.ReadableStream): Promise<Buffer> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = [];
    readableStream.on("data", (data) => {
      chunks.push(data instanceof Buffer ? data : Buffer.from(data));
    });
    readableStream.on("end", () => {
      resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
  });
}

Contoh penggunaan (browser):

import { DataLakeServiceClient } from "@azure/storage-file-datalake";

const account = "<account>";
const sas = "<sas token>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net${sas}`,
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Get file content from position 0 to the end
// In browsers, get downloaded data by accessing downloadResponse.contentAsBlob
const downloadResponse = await fileClient.read();
if (downloadResponse.contentAsBlob) {
  const blob = await downloadResponse.contentAsBlob;
  const downloaded = await blob.text();
  console.log(`Downloaded file content ${downloaded}`);
}
readToBuffer(Buffer, number, number, FileReadToBufferOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Membaca file Data Lake secara paralel dengan buffer. Offset dan hitungan bersifat opsional, teruskan 0 untuk keduanya membaca seluruh file.

Peringatan: Buffer hanya dapat mendukung file hingga sekitar satu gigabyte pada sistem 32-bit atau sekitar dua gigabyte pada sistem 64-bit karena keterbatasan Node.js/V8. Untuk file yang lebih besar dari ukuran ini, pertimbangkan readToFile.

readToBuffer(number, number, FileReadToBufferOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS

Membaca file Data Lake secara paralel dengan buffer. Offset dan hitungan bersifat opsional, teruskan 0 untuk keduanya untuk membaca seluruh file

Peringatan: Buffer hanya dapat mendukung file hingga sekitar satu gigabyte pada sistem 32-bit atau sekitar dua gigabyte pada sistem 64-bit karena keterbatasan Node.js/V8. Untuk file yang lebih besar dari ukuran ini, pertimbangkan readToFile.

readToFile(string, number, number, FileReadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunduh file Data Lake ke file lokal. Gagal jika jalur file yang diberikan sudah keluar. Offset dan hitungan bersifat opsional, pass 0, dan undefined masing-masing untuk mengunduh seluruh file.

setExpiry(PathExpiryOptions, FileSetExpiryOptions)

Mengatur waktu kedaluwarsa pada file, setelah waktu tersebut terpenuhi, file dihapus.

upload(Blob | ArrayBuffer | ArrayBufferView | Buffer, FileParallelUploadOptions)

Mengunggah Buffer(Node.js)/Blob/ArrayBuffer/ArrayBufferView ke File.

uploadFile(string, FileParallelUploadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunggah file lokal ke file Data Lake.

uploadStream(Readable, FileParallelUploadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunggah aliran Node.js dapat dibaca ke dalam file Data Lake. Metode ini akan mencoba membuat file, lalu mulai mengunggah gugus berdasarkan gugus. Pastikan potensi ukuran aliran tidak melebihi FILE_MAX_SIZE_BYTES dan potensi jumlah gugus tidak melebihi BLOCK_BLOB_MAX_BLOCKS.

TIPS PENINGKATAN PERFORMA:

  • Input stream highWaterMark lebih baik mengatur nilai yang sama dengan parameter options.chunkSize, yang akan menghindari operasi Buffer.concat().

Metode yang Diwarisi

delete(boolean, PathDeleteOptions)

Hapus jalur saat ini (direktori atau file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/delete

deleteIfExists(boolean, PathDeleteOptions)

Hapus jalur saat ini (direktori atau file) jika ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/delete

exists(PathExistsOptions)

Mengembalikan true jika file Data Lake yang diwakili oleh klien ini ada; false jika tidak.

CATATAN: gunakan fungsi ini dengan hati-hati karena file yang ada mungkin dihapus oleh klien atau aplikasi lain. Sebaliknya, file baru mungkin ditambahkan oleh klien atau aplikasi lain setelah fungsi ini selesai.

getAccessControl(PathGetAccessControlOptions)

Mengembalikan data kontrol akses untuk jalur (direktori file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/getproperties

getDataLakeLeaseClient(string)

Dapatkan DataLakeLeaseClient yang mengelola sewa di jalur (direktori atau file).

getProperties(PathGetPropertiesOptions)

Mengembalikan semua metadata yang ditentukan pengguna, properti HTTP standar, dan properti sistem untuk jalur (direktori atau file).

PERINGATAN: Objek metadata yang dikembalikan dalam respons akan memiliki kuncinya dalam huruf kecil, bahkan jika awalnya berisi karakter huruf besar. Ini berbeda dari kunci metadata yang dikembalikan oleh metode DataLakeFileSystemClient yang mencantumkan jalur menggunakan opsi includeMetadata, yang akan mempertahankan casing aslinya.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-blob-properties

move(string, PathMoveOptions)

Pindahkan direktori atau file dalam sistem file yang sama.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

move(string, string, PathMoveOptions)

Pindahkan direktori atau file ke sistem file lain.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

removeAccessControlRecursive(RemovePathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Menghapus Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

setAccessControl(PathAccessControlItem[], PathSetAccessControlOptions)

Atur data kontrol akses untuk jalur (direktori file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

setAccessControlRecursive(PathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Mengatur Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

setHttpHeaders(PathHttpHeaders, PathSetHttpHeadersOptions)

Mengatur properti sistem pada jalur (direktori atau file).

Jika tidak ada nilai yang disediakan, atau tidak ada nilai yang disediakan untuk header HTTP blob yang ditentukan, header HTTP blob ini tanpa nilai akan dihapus.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-blob-properties

setMetadata(Metadata, PathSetMetadataOptions)

Mengatur metadata yang ditentukan pengguna untuk jalur yang ditentukan (direktori file) sebagai satu atau beberapa pasangan nilai nama.

Jika tidak ada opsi yang disediakan, atau tidak ada metadata yang ditentukan dalam parameter, metadata jalur akan dihapus.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-blob-metadata

setPermissions(PathPermissions, PathSetPermissionsOptions)

Mengatur izin file pada jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

toDirectoryClient()

Konversikan DataLakePathClient saat ini ke DataLakeDirectoryClient jika jalur saat ini adalah direktori.

toFileClient()

Konversikan DataLakePathClient saat ini ke DataLakeFileClient jika jalur saat ini adalah file.

updateAccessControlRecursive(PathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Memodifikasi Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

Detail Konstruktor

DataLakeFileClient(string, Pipeline)

Membuat instans DataLakeFileClient dari url dan alur.

new DataLakeFileClient(url: string, pipeline: Pipeline)

Parameter

url

string

String Klien yang menunjuk ke file data lake Azure Storage, seperti "https://myaccount.dfs.core.windows.net/filesystem/file". Anda dapat menambahkan SAS jika menggunakan AnonymousCredential, seperti "https://myaccount.dfs.core.windows.net/filesystem/directory/file?sasString".

pipeline
Pipeline

Panggil newPipeline() untuk membuat alur default, atau sediakan alur yang disesuaikan.

DataLakeFileClient(string, StorageSharedKeyCredential | AnonymousCredential | TokenCredential, StoragePipelineOptions)

Membuat instans DataLakeFileClient dari url dan kredensial.

new DataLakeFileClient(url: string, credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential, options?: StoragePipelineOptions)

Parameter

url

string

String Klien yang menunjuk ke file data lake Azure Storage, seperti "https://myaccount.dfs.core.windows.net/filesystem/file". Anda dapat menambahkan SAS jika menggunakan AnonymousCredential, seperti "https://myaccount.dfs.core.windows.net/filesystem/directory/file?sasString".

credential

StorageSharedKeyCredential | AnonymousCredential | TokenCredential

Seperti AnonymousCredential, StorageSharedKeyCredential atau kredensial apa pun dari paket @azure/identity untuk mengautentikasi permintaan ke layanan. Anda juga dapat menyediakan objek yang mengimplementasikan antarmuka TokenCredential. Jika tidak ditentukan, AnonymousCredential digunakan.

options
StoragePipelineOptions

Optional. Opsi untuk mengonfigurasi alur HTTP.

Detail Properti

fileSystemName

Nama sistem file saat ini.

string fileSystemName

Nilai Properti

string

name

Nama jalur saat ini (direktori atau file).

string name

Nilai Properti

string

Detail Properti yang Diwariskan

accountName

accountName: string

Nilai Properti

string

Diwarisi dariDataLakePathClient.accountName

credential

Seperti AnonymousCredential, StorageSharedKeyCredential atau kredensial apa pun dari paket @azure/identity untuk mengautentikasi permintaan ke layanan. Anda juga dapat menyediakan objek yang mengimplementasikan antarmuka TokenCredential. Jika tidak ditentukan, AnonymousCredential digunakan.

credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential

Nilai Properti

Diwarisi dariDataLakePathClient.credential

url

Nilai string URL yang dikodekan.

url: string

Nilai Properti

string

Diwarisi dariDataLakePathClient.url

Detail Metode

append(RequestBodyType, number, number, FileAppendOptions)

Mengunggah data yang akan ditambahkan ke file. Data hanya dapat ditambahkan ke file. Untuk menerapkan data yang diunggah secara pervious ke file, panggil flush.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function append(body: RequestBodyType, offset: number, length: number, options?: FileAppendOptions): Promise<FileAppendResponse>

Parameter

body
HttpRequestBody

Konten yang akan diunggah.

offset

number

Tambahkan offset dalam byte.

length

number

Panjang konten untuk ditambahkan dalam byte.

options
FileAppendOptions

Optional. Opsi saat menambahkan data.

Mengembalikan

create(FileCreateOptions)

Buat file.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function create(options?: FileCreateOptions): Promise<FileCreateResponse>

Parameter

options
FileCreateOptions

Optional. Opsi saat membuat file.

Mengembalikan

create(PathResourceType, PathCreateOptions)

Buat file.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function create(resourceType: PathResourceType, options?: PathCreateOptions): Promise<PathCreateResponse>

Parameter

resourceType
PathResourceTypeModel

Jenis sumber daya, harus "file" untuk DataLakeFileClient.

options
PathCreateOptions

Optional. Opsi saat membuat file.

Mengembalikan

createIfNotExists(FileCreateIfNotExistsOptions)

Buat file jika belum ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function createIfNotExists(options?: FileCreateIfNotExistsOptions): Promise<FileCreateIfNotExistsResponse>

Parameter

options
FileCreateIfNotExistsOptions

Optional. Opsi saat membuat file.

Mengembalikan

createIfNotExists(PathResourceType, PathCreateIfNotExistsOptions)

Buat file jika belum ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function createIfNotExists(resourceType: PathResourceType, options?: PathCreateIfNotExistsOptions): Promise<PathCreateIfNotExistsResponse>

Parameter

resourceType
PathResourceTypeModel

Jenis sumber daya, harus "file" untuk DataLakeFileClient.

Mengembalikan

flush(number, FileFlushOptions)

Menghapus (menulis) data yang sebelumnya ditambahkan ke file.

function flush(position: number, options?: FileFlushOptions): Promise<FileFlushResponse>

Parameter

position

number

Posisi file untuk memerah. Parameter ini memungkinkan pemanggil untuk mengunggah data secara paralel dan mengontrol urutan penambahan ke file. Diperlukan saat mengunggah data untuk ditambahkan ke file dan saat membersihkan data yang diunggah sebelumnya ke file. Nilai harus posisi di mana data akan ditambahkan. Data yang diunggah tidak segera dihapus, atau ditulis, ke file. Untuk membersihkan, data yang diunggah sebelumnya harus bersebelahan, parameter posisi harus ditentukan dan sama dengan panjang file setelah semua data ditulis, dan tidak boleh ada badan entitas permintaan yang disertakan dengan permintaan.

options
FileFlushOptions

Optional. Opsi saat menghapus data.

Mengembalikan

generateSasStringToSign(FileGenerateSasUrlOptions)

Hanya tersedia untuk klien yang dibangun dengan kredensial kunci bersama.

Menghasilkan string untuk masuk ke URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

function generateSasStringToSign(options: FileGenerateSasUrlOptions): string

Parameter

options
FileGenerateSasUrlOptions

Parameter opsional.

Mengembalikan

string

URI SAS yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti dengan token SAS yang dihasilkan.

generateSasUrl(FileGenerateSasUrlOptions)

Hanya tersedia untuk klien yang dibangun dengan kredensial kunci bersama.

Menghasilkan URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kredensial kunci bersama klien.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

function generateSasUrl(options: FileGenerateSasUrlOptions): Promise<string>

Parameter

options
FileGenerateSasUrlOptions

Parameter opsional.

Mengembalikan

Promise<string>

URI SAS yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti dengan token SAS yang dihasilkan.

generateUserDelegationSasStringToSign(FileGenerateSasUrlOptions, UserDelegationKey)

Menghasilkan string untuk masuk ke URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kunci delegasi pengguna input.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

function generateUserDelegationSasStringToSign(options: FileGenerateSasUrlOptions, userDelegationKey: UserDelegationKey): string

Parameter

options
FileGenerateSasUrlOptions

Parameter opsional.

userDelegationKey
UserDelegationKey

Mengembalikan nilai blobServiceClient.getUserDelegationKey()

Mengembalikan

string

URI SAS yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti dengan token SAS yang dihasilkan.

generateUserDelegationSasUrl(FileGenerateSasUrlOptions, UserDelegationKey)

Menghasilkan URI Tanda Tangan Akses Bersama Layanan (SAS) berdasarkan properti klien dan parameter yang diteruskan. SAS ditandatangani oleh kunci delegasi pengguna input.

Lihat https://learn.microsoft.com/rest/api/storageservices/constructing-a-service-sas

function generateUserDelegationSasUrl(options: FileGenerateSasUrlOptions, userDelegationKey: UserDelegationKey): Promise<string>

Parameter

options
FileGenerateSasUrlOptions

Parameter opsional.

userDelegationKey
UserDelegationKey

Mengembalikan nilai blobServiceClient.getUserDelegationKey()

Mengembalikan

Promise<string>

URI SAS yang terdiri dari URI ke sumber daya yang diwakili oleh klien ini, diikuti dengan token SAS yang dihasilkan.

query(string, FileQueryOptions)

Kueri cepat untuk file berformat JSON atau CSV.

Contoh penggunaan (Node.js):

import { DataLakeServiceClient } from "@azure/storage-file-datalake";

const account = "<account>";
const sas = "<sas token>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net${sas}`,
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Query and convert a file to a string
const queryResponse = await fileClient.query("select * from BlobStorage");
if (queryResponse.readableStreamBody) {
  const responseBuffer = await streamToBuffer(queryResponse.readableStreamBody);
  const downloaded = responseBuffer.toString();
  console.log(`Query file content: ${downloaded}`);
}

async function streamToBuffer(readableStream: NodeJS.ReadableStream): Promise<Buffer> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = [];
    readableStream.on("data", (data) => {
      chunks.push(data instanceof Buffer ? data : Buffer.from(data));
    });
    readableStream.on("end", () => {
      resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
  });
}
function query(query: string, options?: FileQueryOptions): Promise<FileReadResponse>

Parameter

query

string

Mengembalikan

Promise<FileReadResponse>

read(number, number, FileReadOptions)

Mengunduh file dari layanan, termasuk metadata dan propertinya.

  • Di Node.js, data kembali dalam aliran yang dapat dibaca ReadableStreamBody
  • Di browser, data kembali dalam konten yang dijanjikanAsBlob

Lihat https://learn.microsoft.com/rest/api/storageservices/get-blob

  • Contoh penggunaan (Node.js):
import { DataLakeServiceClient } from "@azure/storage-file-datalake";
import { DefaultAzureCredential } from "@azure/identity";

const account = "<account>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net`,
  new DefaultAzureCredential(),
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Get file content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadResponse.readableStreamBody
const downloadResponse = await fileClient.read();
if (downloadResponse.readableStreamBody) {
  const downloaded = await streamToBuffer(downloadResponse.readableStreamBody);
  console.log("Downloaded file content:", downloaded.toString());
}

// [Node.js only] A helper method used to read a Node.js readable stream into a Buffer.
async function streamToBuffer(readableStream: NodeJS.ReadableStream): Promise<Buffer> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = [];
    readableStream.on("data", (data) => {
      chunks.push(data instanceof Buffer ? data : Buffer.from(data));
    });
    readableStream.on("end", () => {
      resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
  });
}

Contoh penggunaan (browser):

import { DataLakeServiceClient } from "@azure/storage-file-datalake";

const account = "<account>";
const sas = "<sas token>";
const datalakeServiceClient = new DataLakeServiceClient(
  `https://${account}.dfs.core.windows.net${sas}`,
);

const fileSystemName = "<file system name>";
const fileName = "<file name>";
const fileSystemClient = datalakeServiceClient.getFileSystemClient(fileSystemName);
const fileClient = fileSystemClient.getFileClient(fileName);

// Get file content from position 0 to the end
// In browsers, get downloaded data by accessing downloadResponse.contentAsBlob
const downloadResponse = await fileClient.read();
if (downloadResponse.contentAsBlob) {
  const blob = await downloadResponse.contentAsBlob;
  const downloaded = await blob.text();
  console.log(`Downloaded file content ${downloaded}`);
}
function read(offset?: number, count?: number, options?: FileReadOptions): Promise<FileReadResponse>

Parameter

offset

number

Optional. Offset untuk membaca file, nilai defaultnya adalah 0.

count

number

Optional. Berapa banyak byte yang akan dibaca, default akan dibaca dari offset ke akhir.

options
FileReadOptions

Optional. Opsi saat membaca file.

Mengembalikan

Promise<FileReadResponse>

readToBuffer(Buffer, number, number, FileReadToBufferOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Membaca file Data Lake secara paralel dengan buffer. Offset dan hitungan bersifat opsional, teruskan 0 untuk keduanya membaca seluruh file.

Peringatan: Buffer hanya dapat mendukung file hingga sekitar satu gigabyte pada sistem 32-bit atau sekitar dua gigabyte pada sistem 64-bit karena keterbatasan Node.js/V8. Untuk file yang lebih besar dari ukuran ini, pertimbangkan readToFile.

function readToBuffer(buffer: Buffer, offset?: number, count?: number, options?: FileReadToBufferOptions): Promise<Buffer>

Parameter

buffer

Buffer

Buffer yang akan diisi, harus memiliki panjang yang lebih besar dari hitungan

offset

number

Dari posisi file Data Lake mana yang akan dibaca

count

number

Berapa banyak data yang akan dibaca. Akan membaca ke akhir saat melewati tidak terdefinis

Mengembalikan

Promise<Buffer>

readToBuffer(number, number, FileReadToBufferOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS

Membaca file Data Lake secara paralel dengan buffer. Offset dan hitungan bersifat opsional, teruskan 0 untuk keduanya untuk membaca seluruh file

Peringatan: Buffer hanya dapat mendukung file hingga sekitar satu gigabyte pada sistem 32-bit atau sekitar dua gigabyte pada sistem 64-bit karena keterbatasan Node.js/V8. Untuk file yang lebih besar dari ukuran ini, pertimbangkan readToFile.

function readToBuffer(offset?: number, count?: number, options?: FileReadToBufferOptions): Promise<Buffer>

Parameter

offset

number

Dari posisi file Data Lake mana yang akan dibaca(dalam byte)

count

number

Berapa banyak data(dalam byte) yang akan dibaca. Akan membaca ke akhir saat melewati tidak terdefinis

Mengembalikan

Promise<Buffer>

readToFile(string, number, number, FileReadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunduh file Data Lake ke file lokal. Gagal jika jalur file yang diberikan sudah keluar. Offset dan hitungan bersifat opsional, pass 0, dan undefined masing-masing untuk mengunduh seluruh file.

function readToFile(filePath: string, offset?: number, count?: number, options?: FileReadOptions): Promise<FileReadResponse>

Parameter

filePath

string

offset

number

Dari posisi file mana yang akan diunduh.

count

number

Berapa banyak data yang akan diunduh. Akan mengunduh ke akhir saat melewati tidak ditentukan.

options
FileReadOptions

Opsi untuk membaca file Data Lake.

Mengembalikan

Promise<FileReadResponse>

Data respons untuk operasi baca file, tetapi dengan readableStreamBody diatur ke tidak terdefinisi karena kontennya sudah dibaca dan ditulis ke dalam file lokal di jalur yang ditentukan.

setExpiry(PathExpiryOptions, FileSetExpiryOptions)

Mengatur waktu kedaluwarsa pada file, setelah waktu tersebut terpenuhi, file dihapus.

function setExpiry(mode: PathExpiryOptions, options?: FileSetExpiryOptions): Promise<FileSetExpiryResponse>

Parameter

Mengembalikan

upload(Blob | ArrayBuffer | ArrayBufferView | Buffer, FileParallelUploadOptions)

Mengunggah Buffer(Node.js)/Blob/ArrayBuffer/ArrayBufferView ke File.

function upload(data: Blob | ArrayBuffer | ArrayBufferView | Buffer, options?: FileParallelUploadOptions): Promise<FileUploadResponse>

Parameter

data

Blob | ArrayBuffer | ArrayBufferView | Buffer

Buffer(Node), Blob, ArrayBuffer atau ArrayBufferView

Mengembalikan

uploadFile(string, FileParallelUploadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunggah file lokal ke file Data Lake.

function uploadFile(filePath: string, options?: FileParallelUploadOptions): Promise<FileUploadResponse>

Parameter

filePath

string

Jalur lengkap file lokal

Mengembalikan

uploadStream(Readable, FileParallelUploadOptions)

HANYA TERSEDIA DALAM RUNTIME NODE.JS.

Mengunggah aliran Node.js dapat dibaca ke dalam file Data Lake. Metode ini akan mencoba membuat file, lalu mulai mengunggah gugus berdasarkan gugus. Pastikan potensi ukuran aliran tidak melebihi FILE_MAX_SIZE_BYTES dan potensi jumlah gugus tidak melebihi BLOCK_BLOB_MAX_BLOCKS.

TIPS PENINGKATAN PERFORMA:

  • Input stream highWaterMark lebih baik mengatur nilai yang sama dengan parameter options.chunkSize, yang akan menghindari operasi Buffer.concat().
function uploadStream(stream: Readable, options?: FileParallelUploadOptions): Promise<FileUploadResponse>

Parameter

stream

Readable

Node.js aliran yang dapat dibaca.

Mengembalikan

Detail Metode yang Diwarisi

delete(boolean, PathDeleteOptions)

Hapus jalur saat ini (direktori atau file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/delete

function delete(recursive?: boolean, options?: PathDeleteOptions): Promise<PathDeleteResponse>

Parameter

recursive

boolean

Diperlukan dan valid hanya ketika sumber daya adalah direktori. Jika "true", semua jalur di bawah direktori akan dihapus.

options
PathDeleteOptions

Optional. Opsi saat menghapus jalur.

Mengembalikan

Diwarisi dariDataLakePathClient.delete

deleteIfExists(boolean, PathDeleteOptions)

Hapus jalur saat ini (direktori atau file) jika ada.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/delete

function deleteIfExists(recursive?: boolean, options?: PathDeleteOptions): Promise<PathDeleteIfExistsResponse>

Parameter

recursive

boolean

Diperlukan dan valid hanya ketika sumber daya adalah direktori. Jika "true", semua jalur di bawah direktori akan dihapus.

Mengembalikan

Diwarisi dariDataLakePathClient.deleteIfExists

exists(PathExistsOptions)

Mengembalikan true jika file Data Lake yang diwakili oleh klien ini ada; false jika tidak.

CATATAN: gunakan fungsi ini dengan hati-hati karena file yang ada mungkin dihapus oleh klien atau aplikasi lain. Sebaliknya, file baru mungkin ditambahkan oleh klien atau aplikasi lain setelah fungsi ini selesai.

function exists(options?: PathExistsOptions): Promise<boolean>

Parameter

options
PathExistsOptions

opsi untuk operasi Ada.

Mengembalikan

Promise<boolean>

Diwarisi dariDataLakePathClient.exists

getAccessControl(PathGetAccessControlOptions)

Mengembalikan data kontrol akses untuk jalur (direktori file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/getproperties

function getAccessControl(options?: PathGetAccessControlOptions): Promise<PathGetAccessControlResponse>

Parameter

options
PathGetAccessControlOptions

Optional. Opsi saat mendapatkan kontrol akses file.

Mengembalikan

Diwarisi dariDataLakePathClient.getAccessControl

getDataLakeLeaseClient(string)

Dapatkan DataLakeLeaseClient yang mengelola sewa di jalur (direktori atau file).

function getDataLakeLeaseClient(proposeLeaseId?: string): DataLakeLeaseClient

Parameter

proposeLeaseId

string

Optional. Id sewa awal yang diusulkan.

Mengembalikan

Diwarisi dariDataLakePathClient.getDataLakeLeaseClient

getProperties(PathGetPropertiesOptions)

Mengembalikan semua metadata yang ditentukan pengguna, properti HTTP standar, dan properti sistem untuk jalur (direktori atau file).

PERINGATAN: Objek metadata yang dikembalikan dalam respons akan memiliki kuncinya dalam huruf kecil, bahkan jika awalnya berisi karakter huruf besar. Ini berbeda dari kunci metadata yang dikembalikan oleh metode DataLakeFileSystemClient yang mencantumkan jalur menggunakan opsi includeMetadata, yang akan mempertahankan casing aslinya.

Lihat https://learn.microsoft.com/rest/api/storageservices/get-blob-properties

function getProperties(options?: PathGetPropertiesOptions): Promise<PathGetPropertiesResponse>

Parameter

options
PathGetPropertiesOptions

Optional. Opsi saat mendapatkan properti jalur.

Mengembalikan

Diwarisi dariDataLakePathClient.getProperties

move(string, PathMoveOptions)

Pindahkan direktori atau file dalam sistem file yang sama.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function move(destinationPath: string, options?: PathMoveOptions): Promise<PathMoveResponse>

Parameter

destinationPath

string

Jalur direktori tujuan seperti "direktori" atau jalur file "direktori/file". Jika destinationPath diautentikasi dengan SAS, tambahkan SAS ke jalur tujuan seperti "directory/file?sasToken".

options
PathMoveOptions

Optional. Opsi saat memindahkan direktori atau file.

Mengembalikan

Promise<PathMoveResponse>

Diwarisi dariDataLakePathClient.move

move(string, string, PathMoveOptions)

Pindahkan direktori atau file ke sistem file lain.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/create

function move(destinationFileSystem: string, destinationPath: string, options?: PathMoveOptions): Promise<PathMoveResponse>

Parameter

destinationFileSystem

string

Sistem file tujuan seperti "sistem file".

destinationPath

string

Jalur direktori tujuan seperti "direktori" atau jalur file "direktori/file" Jika destinationPath diautentikasi dengan SAS, tambahkan SAS ke jalur tujuan seperti "direktori/file?sasToken".

options
PathMoveOptions

Optional. Opsi saat memindahkan direktori atau file.

Mengembalikan

Promise<PathMoveResponse>

Diwarisi dariDataLakePathClient.move

removeAccessControlRecursive(RemovePathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Menghapus Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function removeAccessControlRecursive(acl: RemovePathAccessControlItem[], options?: PathChangeAccessControlRecursiveOptions): Promise<PathChangeAccessControlRecursiveResponse>

Parameter

acl

RemovePathAccessControlItem[]

Daftar kontrol akses POSIX untuk file atau direktori.

Mengembalikan

Diwarisi dariDataLakePathClient.removeAccessControlRecursive

setAccessControl(PathAccessControlItem[], PathSetAccessControlOptions)

Atur data kontrol akses untuk jalur (direktori file).

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function setAccessControl(acl: PathAccessControlItem[], options?: PathSetAccessControlOptions): Promise<PathSetAccessControlResponse>

Parameter

acl

PathAccessControlItem[]

Daftar kontrol akses POSIX untuk file atau direktori.

options
PathSetAccessControlOptions

Optional. Opsi saat mengatur kontrol akses jalur.

Mengembalikan

Diwarisi dariDataLakePathClient.setAccessControl

setAccessControlRecursive(PathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Mengatur Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function setAccessControlRecursive(acl: PathAccessControlItem[], options?: PathChangeAccessControlRecursiveOptions): Promise<PathChangeAccessControlRecursiveResponse>

Parameter

acl

PathAccessControlItem[]

Daftar kontrol akses POSIX untuk file atau direktori.

Mengembalikan

Diwarisi dariDataLakePathClient.setAccessControlRecursive

setHttpHeaders(PathHttpHeaders, PathSetHttpHeadersOptions)

Mengatur properti sistem pada jalur (direktori atau file).

Jika tidak ada nilai yang disediakan, atau tidak ada nilai yang disediakan untuk header HTTP blob yang ditentukan, header HTTP blob ini tanpa nilai akan dihapus.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-blob-properties

function setHttpHeaders(httpHeaders: PathHttpHeaders, options?: PathSetHttpHeadersOptions): Promise<PathSetHttpHeadersResponse>

Parameter

httpHeaders
PathHttpHeaders

Mengembalikan

Diwarisi dariDataLakePathClient.setHttpHeaders

setMetadata(Metadata, PathSetMetadataOptions)

Mengatur metadata yang ditentukan pengguna untuk jalur yang ditentukan (direktori file) sebagai satu atau beberapa pasangan nilai nama.

Jika tidak ada opsi yang disediakan, atau tidak ada metadata yang ditentukan dalam parameter, metadata jalur akan dihapus.

Lihat https://learn.microsoft.com/rest/api/storageservices/set-blob-metadata

function setMetadata(metadata?: Metadata, options?: PathSetMetadataOptions): Promise<PathSetMetadataResponse>

Parameter

metadata
Metadata

Optional. Ganti metadata yang ada dengan nilai ini. Jika tidak ada nilai yang disediakan, metadata yang ada akan dihapus.

options
PathSetMetadataOptions

Optional. Opsi saat mengatur metadata jalur.

Mengembalikan

Diwarisi dariDataLakePathClient.setMetadata

setPermissions(PathPermissions, PathSetPermissionsOptions)

Mengatur izin file pada jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function setPermissions(permissions: PathPermissions, options?: PathSetPermissionsOptions): Promise<PathSetPermissionsResponse>

Parameter

permissions
PathPermissions

Izin akses POSIX untuk pemilik file, grup pemilik file, dan lainnya.

options
PathSetPermissionsOptions

Optional. Opsi saat mengatur izin jalur.

Mengembalikan

Diwarisi dariDataLakePathClient.setPermissions

toDirectoryClient()

Konversikan DataLakePathClient saat ini ke DataLakeDirectoryClient jika jalur saat ini adalah direktori.

function toDirectoryClient(): DataLakeDirectoryClient

Mengembalikan

Diwarisi dariDataLakePathClient.toDirectoryClient

toFileClient()

Konversikan DataLakePathClient saat ini ke DataLakeFileClient jika jalur saat ini adalah file.

function toFileClient(): DataLakeFileClient

Mengembalikan

Diwarisi dariDataLakePathClient.toFileClient

updateAccessControlRecursive(PathAccessControlItem[], PathChangeAccessControlRecursiveOptions)

Memodifikasi Kontrol Akses pada jalur dan sub jalur.

Lihat https://learn.microsoft.com/rest/api/storageservices/datalakestoragegen2/path/update

function updateAccessControlRecursive(acl: PathAccessControlItem[], options?: PathChangeAccessControlRecursiveOptions): Promise<PathChangeAccessControlRecursiveResponse>

Parameter

acl

PathAccessControlItem[]

Daftar kontrol akses POSIX untuk file atau direktori.

Mengembalikan

Diwarisi dariDataLakePathClient.updateAccessControlRecursive