Skip to content

Commit

Permalink
Prepare Storage packages to move to @types/node v12 (#16020)
Browse files Browse the repository at this point in the history
* Use BufferEncoding as encoding is not a string in Node.js 12

* Fix typing issue for fsStat returning unknown
  • Loading branch information
ramya-rao-a authored Jun 28, 2021
1 parent b8da289 commit ff90eba
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
6 changes: 3 additions & 3 deletions sdk/storage/storage-blob/src/utils/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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 @@ -72,7 +72,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 @@ -113,7 +113,7 @@ export async function streamToBuffer2(
*/
export async function streamToBuffer3(
readableStream: NodeJS.ReadableStream,
encoding?: string
encoding?: BufferEncoding
): Promise<Buffer> {
return new Promise((resolve, reject) => {
const chunks: Buffer[] = [];
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-common/src/BufferScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class BufferScheduler {
/**
* Encoding of the input Readable stream which has string data type instead of Buffer.
*/
private encoding?: string;
private encoding?: BufferEncoding;

/**
* How many buffers have been allocated.
Expand Down Expand Up @@ -141,7 +141,7 @@ export class BufferScheduler {
maxBuffers: number,
outgoingHandler: OutgoingHandler,
concurrency: number,
encoding?: string
encoding?: BufferEncoding
) {
if (bufferSize <= 0) {
throw new RangeError(`bufferSize must be larger than 0, current is ${bufferSize}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class BufferScheduler {
/**
* Encoding of the input Readable stream which has string data type instead of Buffer.
*/
private encoding?: string;
private encoding?: BufferEncoding;

/**
* How many buffers have been allocated.
Expand Down Expand Up @@ -136,7 +136,7 @@ export class BufferScheduler {
maxBuffers: number,
outgoingHandler: OutgoingHandler,
concurrency: number,
encoding?: string
encoding?: BufferEncoding
) {
if (bufferSize <= 0) {
throw new RangeError(`bufferSize must be larger than 0, current is ${bufferSize}`);
Expand Down
7 changes: 3 additions & 4 deletions sdk/storage/storage-file-datalake/src/utils/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

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 +18,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 +72,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 @@ -110,6 +109,6 @@ export async function streamToBuffer2(
*
* Promisified version of fs.stat().
*/
export const fsStat = util.promisify(isNode ? fs.stat : function stat() {});
export const fsStat = util.promisify(fs.stat);

export const fsCreateReadStream = fs.createReadStream;
4 changes: 2 additions & 2 deletions sdk/storage/storage-file-share/src/utils/BufferScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class BufferScheduler {
/**
* Encoding of the input Readable stream which has string data type instead of Buffer.
*/
private encoding?: string;
private encoding?: BufferEncoding;

/**
* How many buffers have been allocated.
Expand Down Expand Up @@ -136,7 +136,7 @@ export class BufferScheduler {
maxBuffers: number,
outgoingHandler: OutgoingHandler,
concurrency: number,
encoding?: string
encoding?: BufferEncoding
) {
if (bufferSize <= 0) {
throw new RangeError(`bufferSize must be larger than 0, current is ${bufferSize}`);
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-file-share/src/utils/utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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

0 comments on commit ff90eba

Please sign in to comment.