build single test bunding using Webpack context
This commit is contained in:
parent
b72cf7c04b
commit
ade4216642
8 changed files with 81 additions and 31 deletions
|
@ -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 {
|
||||
|
|
Reference in a new issue