diff --git a/static/js/app.js b/static/js/app.js index a6162a2b3..be76f1664 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -235,6 +235,26 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading }; dataFileService.tryAsTarGz_ = function(buf, success, failure) { + var gunzip = new Zlib.Gunzip(buf); + var plain = null; + + try { + plain = gunzip.decompress(); + } catch (e) { + failure(); + return; + } + + dataFileService.arrayToString(plain, function(result) { + if (result) { + dataFileService.tryAsTarGzWithStringData_(result, success, failure); + } else { + failure(); + } + }); + }; + + dataFileService.tryAsTarGzWithStringData_ = function(strData, success, failure) { var collapsePath = function(originalPath) { // Tar files can contain entries of the form './', so we need to collapse // those paths down. @@ -248,12 +268,9 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading return parts.join('/'); }; - var gunzip = new Zlib.Gunzip(buf); - var plain = gunzip.decompress(); - var handler = new MultiFile(); handler.files = []; - handler.processTarChunks(dataFileService.arrayToString(plain), 0); + handler.processTarChunks(strData, 0); if (!handler.files.length) { failure(); return; @@ -288,8 +305,19 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading reader.readAsText(blob); }; - dataFileService.arrayToString = function(buf) { - return String.fromCharCode.apply(null, new Uint16Array(buf)); + dataFileService.arrayToString = function(buf, callback) { + var bb = new Blob([buf], {type: 'application/octet-binary'}); + var f = new FileReader(); + f.onload = function(e) { + callback(e.target.result); + }; + f.onerror = function(e) { + callback(null); + }; + f.onabort = function(e) { + callback(null); + }; + f.readAsText(bb); }; dataFileService.readDataArrayAsPossibleArchive = function(buf, success, failure) { diff --git a/static/js/controllers.js b/static/js/controllers.js index ad97a6042..7d36ec8fb 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -841,7 +841,7 @@ function BuildPackageCtrl($scope, Restangular, ApiService, DataFileService, $rou if (dockerfile && dockerfile.canRead) { DataFileService.blobToString(dockerfile.toBlob(), function(result) { $scope.$apply(function() { - $scope.dockerFilePath = dockerfilePath; + $scope.dockerFilePath = dockerfilePath || 'Dockerfile'; $scope.dockerFileContents = result; }); }); @@ -851,8 +851,11 @@ function BuildPackageCtrl($scope, Restangular, ApiService, DataFileService, $rou }; var notarchive = function() { - $scope.dockerFileContents = DataFileService.arrayToString(uint8array); - $scope.loaded = true; + DataFileService.arrayToString(uint8array, function(r) { + $scope.dockerFilePath = 'Dockerfile'; + $scope.dockerFileContents = r; + $scope.loaded = true; + }); }; DataFileService.readDataArrayAsPossibleArchive(uint8array, archiveread, notarchive);