Skip to content

Commit

Permalink
Similar fixes for storage-file-datalake
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jun 26, 2021
1 parent 95e0c4e commit 48d8c02
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
2 changes: 1 addition & 1 deletion sdk/storage/storage-file-datalake/rollup.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function browserConfig(test = false) {
shim({
dotenv: `export function config() { }`,
fs: `
export function stat() { }
export function statSync() { }
export function createReadStream() { }
export function createWriteStream() { }
`,
Expand Down
6 changes: 4 additions & 2 deletions sdk/storage/storage-file-datalake/src/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ import {
setURLPath,
setURLQueries
} from "./utils/utils.common";
import { fsCreateReadStream, fsStat } from "./utils/utils.node";
import { fsCreateReadStream } from "./utils/utils.node";
import { statSync } from "fs";

/**
* A DataLakePathClient represents a URL to the Azure Storage path (directory or file).
Expand Down Expand Up @@ -1432,7 +1433,8 @@ export class DataLakeFileClient extends DataLakePathClient {
): Promise<FileUploadResponse> {
const { span, updatedOptions } = createSpan("DataLakeFileClient-uploadFile", options);
try {
const size = (await fsStat(filePath)).size;
const stats = statSync(filePath);
const size = stats.size;
return await this.uploadSeekableInternal(
(offset: number, size: number) => {
return () =>
Expand Down
13 changes: 2 additions & 11 deletions sdk/storage/storage-file-datalake/src/utils/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the MIT license.

import * as fs from "fs";
import * as util from "util";
import { isNode } from "@azure/core-http";

/**
* Reads a readable stream into buffer. Fill the buffer from offset to end.
Expand All @@ -19,7 +17,7 @@ export async function streamToBuffer(
buffer: Buffer,
offset: number,
end: number,
encoding?: string
encoding?: BufferEncoding
): Promise<void> {
let pos = 0; // Position in stream
const count = end - offset; // Total amount of data needed in stream
Expand Down Expand Up @@ -73,7 +71,7 @@ export async function streamToBuffer(
export async function streamToBuffer2(
stream: NodeJS.ReadableStream,
buffer: Buffer,
encoding?: string
encoding?: BufferEncoding
): Promise<number> {
let pos = 0; // Position in stream
const bufferSize = buffer.length;
Expand Down Expand Up @@ -105,11 +103,4 @@ export async function streamToBuffer2(
});
}

/**
* ONLY AVAILABLE IN NODE.JS RUNTIME.
*
* Promisified version of fs.stat().
*/
export const fsStat = util.promisify(isNode ? fs.stat : function stat() {});

export const fsCreateReadStream = fs.createReadStream;

0 comments on commit 48d8c02

Please sign in to comment.