build single test bunding using Webpack context

This commit is contained in:
alecmerdler 2017-03-11 16:48:05 -08:00
parent b72cf7c04b
commit ade4216642
8 changed files with 81 additions and 31 deletions

View file

@ -1,23 +1,36 @@
import { DatafileService } from './datafile.service';
import { DataFileService } from './datafile.service';
import { Injectable } from 'angular-ts-decorators';
declare const JSZip: (buf: any) => void;
declare const Zlib: any;
declare const Untar: (uint8Array: Uint8Array) => void;
export class DatafileServiceImpl implements DatafileService {
@Injectable(DataFileService.name)
export class DataFileServiceImpl implements DataFileService {
public blobToString(blob: any, callback: (result: string) => void): void {
var reader: FileReader = new FileReader();
reader.onload = (event: Event) => callback(reader.result);
reader.readAsText(blob);
}
public arrayToString(buf: any, callback: (result: string) => void): void {
var blob: Blob = new Blob([buf], {type: 'application/octet-binary'});
var reader = new FileReader();
reader.onload = (event: Event) => callback(event.target['result']);
reader.onerror = (event: Event) => callback(null);
reader.onabort = (event: Event) => callback(null);
reader.readAsText(blob);
}
public readDataArrayAsPossibleArchive(buf: any,
success: (result: any) => void,
failure: (error: any) => void): void {
this.tryAsZip(buf, success, () => {
this.tryAsTarGz(buf, success, () => {
this.tryAsTar(buf, success, failure);
});
});
}
public downloadDataFileAsArrayBuffer($scope: ng.IScope,
@ -25,7 +38,36 @@ export class DatafileServiceImpl implements DatafileService {
progress: (percent: number) => void,
error: () => void,
loaded: (uint8array: Uint8Array) => void): void {
var request: XMLHttpRequest = new XMLHttpRequest();
request.open('GET', url, true);
request.responseType = 'arraybuffer';
request.onprogress = (e) => {
$scope.$apply(() => {
var percentLoaded;
if (e.lengthComputable) {
progress(e.loaded / e.total);
}
});
};
request.onerror = () => {
$scope.$apply(() => {
error();
});
};
request.onload = function() {
if (request.status == 200) {
$scope.$apply(() => {
var uint8array = new Uint8Array(request.response);
loaded(uint8array);
});
return;
}
};
request.send();
}
private getName(filePath: string): string {