OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2013 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/extras/importer/jszip.html"> | 8 <link rel="import" href="/tracing/extras/importer/jszip.html"> |
9 <link rel="import" href="/tracing/importer/importer.html"> | 9 <link rel="import" href="/tracing/importer/importer.html"> |
10 <link rel="import" href="/tracing/model/model.html"> | 10 <link rel="import" href="/tracing/model/model.html"> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (have_file_name) | 106 if (have_file_name) |
107 skipZeroTerminatedString(); | 107 skipZeroTerminatedString(); |
108 if (have_comment) | 108 if (have_comment) |
109 skipZeroTerminatedString(); | 109 skipZeroTerminatedString(); |
110 if (have_header_crc) | 110 if (have_header_crc) |
111 getWord(); | 111 getWord(); |
112 | 112 |
113 // Inflate the data using jszip. | 113 // Inflate the data using jszip. |
114 var inflated_data = | 114 var inflated_data = |
115 JSZip.compressions['DEFLATE'].uncompress(data.subarray(position)); | 115 JSZip.compressions['DEFLATE'].uncompress(data.subarray(position)); |
116 return JSZip.utils.transformTo('string', inflated_data); | 116 return GzipImporter.transformToString(inflated_data); |
117 }, | 117 }; |
| 118 |
| 119 /** |
| 120 * Transforms an array-like object to a string. |
| 121 * |
| 122 * Note that the following two expressions yield identical results: |
| 123 * |
| 124 * GzipImporter.transformToString_(data) |
| 125 * JSZip.utils.transformTo('string', data) |
| 126 * |
| 127 * We use a custom static method because it is faster and, more importantly, |
| 128 * avoids OOMing on large traces. See |
| 129 * https://github.com/catapult-project/catapult/issues/2051. |
| 130 */ |
| 131 GzipImporter.transformToString = function(data) { |
| 132 if (typeof TextDecoder === 'undefined') { |
| 133 // Fall back to jszip if TextDecoder is not available. |
| 134 return JSZip.utils.transformTo('string', data); |
| 135 } |
| 136 |
| 137 var type = JSZip.utils.getTypeOf(data); |
| 138 if (type === 'string') |
| 139 return data; // We already have a string. |
| 140 |
| 141 if (type === 'array') { |
| 142 // TextDecoder requires an ArrayBuffer or an ArrayBufferView. |
| 143 data = new Uint8Array(data); |
| 144 } |
| 145 |
| 146 var decoder = new TextDecoder('utf-8'); |
| 147 return decoder.decode(data); |
| 148 }; |
118 | 149 |
119 GzipImporter.prototype = { | 150 GzipImporter.prototype = { |
120 __proto__: tr.importer.Importer.prototype, | 151 __proto__: tr.importer.Importer.prototype, |
121 | 152 |
122 get importerName() { | 153 get importerName() { |
123 return 'GzipImporter'; | 154 return 'GzipImporter'; |
124 }, | 155 }, |
125 | 156 |
126 /** | 157 /** |
127 * Called by the Model to check whether the importer just encapsulates | 158 * Called by the Model to check whether the importer just encapsulates |
(...skipping 13 matching lines...) Expand all Loading... |
141 } | 172 } |
142 }; | 173 }; |
143 | 174 |
144 tr.importer.Importer.register(GzipImporter); | 175 tr.importer.Importer.register(GzipImporter); |
145 | 176 |
146 return { | 177 return { |
147 GzipImporter: GzipImporter | 178 GzipImporter: GzipImporter |
148 }; | 179 }; |
149 }); | 180 }); |
150 </script> | 181 </script> |
OLD | NEW |