Fix encoding during zipfile download

This commit is contained in:
Tiago Koji Castro Shibata 2018-08-03 20:38:22 -07:00
Родитель 895b9c9a71
Коммит 6306ce5200
2 изменённых файлов: 2 добавлений и 5 удалений

Просмотреть файл

@ -39,14 +39,12 @@ function unzip(buffer: Buffer, directory: string, success: () => void, errorCall
}
zipfile!.once('end', success);
zipfile!.once('error', errorCallback);
zipfile!.readEntry();
zipfile!.on('entry', entry => {
zipfile!.openReadStream(entry, (error, readStream) => {
if (error) {
errorCallback(error);
return;
}
readStream!.on('end', zipfile!.readEntry);
readStream!.once('error', errorCallback);
readStream!.pipe(fs.createWriteStream(path.join(directory, entry.fileName)));
});
@ -63,7 +61,7 @@ export function downloadPython(success: () => void, error: (err: Error) => void)
const data: Buffer[] = [];
https.get(pythonUrl, response => {
response
.on('data', data.push)
.on('data', (x: string) => data.push(Buffer.from(x, 'binary')))
.on('end', () => unzip(Buffer.concat(data), pythonFolder, success, error))
.on('error', error);
});

Просмотреть файл

@ -1,4 +1,3 @@
// tslint:disable:no-console
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';
import { ChoiceGroup, IChoiceGroupOption } from 'office-ui-fabric-react/lib/ChoiceGroup';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
@ -60,7 +59,6 @@ export default class ConvertView extends React.Component<{}, IComponentState> {
private pythonChooser = () => {
const binaries = getPythonBinaries();
console.log(binaries);
const options = binaries.map((key) => key ? { key, text: key } : { key: '__download', text: 'Download a new Python binary to be used exclusively by the WinML Dashboard' });
const onChange = (ev: React.FormEvent<HTMLInputElement>, option: IChoiceGroupOption) => {
if (option.key === '__download') {
@ -92,6 +90,7 @@ export default class ConvertView extends React.Component<{}, IComponentState> {
private convert = () => {
// Dialog box
// python
// tslint:disable-next-line:no-console
console.log('Convert')
}
}