1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 * @fileoverview ZipImporter inflates zip compressed data and passes it along
9 * to an actual importer.
11 tvcm.requireRawScript('jszip.js');
12 tvcm.requireRawScript('jszip-load.js');
13 tvcm.requireRawScript('jszip-inflate.js');
15 tvcm.require('tracing.importer.importer');
16 tvcm.require('tracing.importer.gzip_importer');
17 tvcm.require('tracing.trace_model');
19 tvcm.exportTo('tracing.importer', function() {
20 var Importer = tracing.importer.Importer;
22 function ZipImporter(model, eventData) {
23 if (eventData instanceof ArrayBuffer)
24 eventData = new Uint8Array(eventData);
26 this.eventData_ = eventData;
30 * @param {eventData} string Possibly zip compressed data.
31 * @return {boolean} Whether eventData looks like zip compressed data.
33 ZipImporter.canImport = function(eventData) {
35 if (eventData instanceof ArrayBuffer)
36 header = new Uint8Array(eventData.slice(0, 2));
37 else if (typeof(eventData) === 'string' || eventData instanceof String)
38 header = [eventData.charCodeAt(0), eventData.charCodeAt(1)];
41 return header[0] === 'P'.charCodeAt(0) && header[1] === 'K'.charCodeAt(0);
44 ZipImporter.prototype = {
45 __proto__: Importer.prototype,
47 extractSubtraces: function() {
48 var zip = new JSZip(this.eventData_);
50 for (var idx in zip.files)
51 subtraces.push(zip.files[idx].asText());
56 tracing.TraceModel.registerImporter(ZipImporter);
59 ZipImporter: ZipImporter