mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 11:38:36 -05:00
Merge from master
This commit is contained in:
@@ -3,38 +3,34 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as fs from 'fs';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
|
||||
export interface ReadResult {
|
||||
buffer: NodeBuffer;
|
||||
buffer: Buffer | null;
|
||||
bytesRead: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads totalBytes from the provided file.
|
||||
*/
|
||||
export function readExactlyByFile(file: string, totalBytes: number): TPromise<ReadResult> {
|
||||
return new TPromise<ReadResult>((complete, error) => {
|
||||
export function readExactlyByFile(file: string, totalBytes: number): Promise<ReadResult> {
|
||||
return new Promise<ReadResult>((resolve, reject) => {
|
||||
fs.open(file, 'r', null, (err, fd) => {
|
||||
if (err) {
|
||||
return error(err);
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
function end(err: Error, resultBuffer: NodeBuffer, bytesRead: number): void {
|
||||
function end(err: Error | null, resultBuffer: Buffer | null, bytesRead: number): void {
|
||||
fs.close(fd, closeError => {
|
||||
if (closeError) {
|
||||
return error(closeError);
|
||||
return reject(closeError);
|
||||
}
|
||||
|
||||
if (err && (<any>err).code === 'EISDIR') {
|
||||
return error(err); // we want to bubble this error up (file is actually a folder)
|
||||
return reject(err); // we want to bubble this error up (file is actually a folder)
|
||||
}
|
||||
|
||||
return complete({ buffer: resultBuffer, bytesRead });
|
||||
return resolve({ buffer: resultBuffer, bytesRead });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,24 +71,24 @@ export function readExactlyByFile(file: string, totalBytes: number): TPromise<Re
|
||||
* @param maximumBytesToRead The maximum number of bytes to read before giving up.
|
||||
* @param callback The finished callback.
|
||||
*/
|
||||
export function readToMatchingString(file: string, matchingString: string, chunkBytes: number, maximumBytesToRead: number): TPromise<string> {
|
||||
return new TPromise<string>((complete, error) =>
|
||||
export function readToMatchingString(file: string, matchingString: string, chunkBytes: number, maximumBytesToRead: number): Promise<string | null> {
|
||||
return new Promise<string | null>((resolve, reject) =>
|
||||
fs.open(file, 'r', null, (err, fd) => {
|
||||
if (err) {
|
||||
return error(err);
|
||||
return reject(err);
|
||||
}
|
||||
|
||||
function end(err: Error, result: string): void {
|
||||
function end(err: Error | null, result: string | null): void {
|
||||
fs.close(fd, closeError => {
|
||||
if (closeError) {
|
||||
return error(closeError);
|
||||
return reject(closeError);
|
||||
}
|
||||
|
||||
if (err && (<any>err).code === 'EISDIR') {
|
||||
return error(err); // we want to bubble this error up (file is actually a folder)
|
||||
return reject(err); // we want to bubble this error up (file is actually a folder)
|
||||
}
|
||||
|
||||
return complete(result);
|
||||
return resolve(result);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user