pulling max bytes of data through the webhdfs api (#4314)

* pulling max bytes of data through the webhdfs api

* Added warning message for the Users to inform the data truncation.

* Updated the warning message on the notification flyer.
This commit is contained in:
Maddy
2019-03-12 10:38:34 -07:00
committed by GitHub
parent 2397df7f22
commit 77a3be6fd7

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
'use strict'; 'use strict';
import * as vscode from 'vscode';
import * as fspath from 'path'; import * as fspath from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import * as meter from 'stream-meter'; import * as meter from 'stream-meter';
@@ -187,18 +188,25 @@ export class HdfsFileSource implements IFileSource {
reject(error); reject(error);
}); });
let data: any[] = [];
if (maxBytes) { if (maxBytes) {
remoteFileStream = remoteFileStream.pipe(meter(maxBytes)); remoteFileStream = remoteFileStream.pipe(meter(maxBytes));
remoteFileStream.on('error', (err) => { remoteFileStream.on('error', (err) => {
error = <HdfsError>err; error = <HdfsError>err;
if (error.message.includes('Stream exceeded specified max')) { if (error.message.includes('Stream exceeded specified max')) {
error.message = localize('maxSizeReached', 'File exceeds max size of ${0}', bytes(maxBytes)); // We have data > maxbytes, show we're truncating
let previewNote: string = '#################################################################################################################### \r\n'+
'########################### NOTICE: This file has been truncated at '+ bytes(maxBytes) +' for preview ################################ \r\n' +
'#################################################################################################################### \r\n';
data.splice(0, 0, Buffer.from(previewNote, 'utf-8'));
vscode.window.showWarningMessage(localize('maxSizeReached', "The file has been truncated at {0} for preview.", bytes(maxBytes)));
resolve(Buffer.concat(data));
} else {
reject(error);
} }
reject(error);
}); });
} }
let data: any[] = [];
remoteFileStream.on('data', (chunk) => { remoteFileStream.on('data', (chunk) => {
data.push(chunk); data.push(chunk);
}); });