Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: ui/file_manager/zip_archiver/js/compressor.js

Issue 2807063002: Replace Libarchive with MiniZip. (Closed)
Patch Set: Fix a few nits. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium OS Authors. All rights reserved. 1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * A class that takes care of communication with NaCL and creates an archive. 8 * A class that takes care of communication with NaCL and creates an archive.
9 * One instance of this class is created for each pack request. Since multiple 9 * One instance of this class is created for each pack request. Since multiple
10 * compression requests can be in progress at the same time, each instance has 10 * compression requests can be in progress at the same time, each instance has
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 282
283 var entryId = this.pendingAddToArchiveRequests_.shift(); 283 var entryId = this.pendingAddToArchiveRequests_.shift();
284 this.entryIdInProgress_ = entryId; 284 this.entryIdInProgress_ = entryId;
285 285
286 // Convert the absolute path on the virtual filesystem to a relative path from 286 // Convert the absolute path on the virtual filesystem to a relative path from
287 // the archive root by removing the leading '/' if exists. 287 // the archive root by removing the leading '/' if exists.
288 var fullPath = this.entries_[entryId].fullPath; 288 var fullPath = this.entries_[entryId].fullPath;
289 if (fullPath.length && fullPath[0] == '/') 289 if (fullPath.length && fullPath[0] == '/')
290 fullPath = fullPath.substring(1); 290 fullPath = fullPath.substring(1);
291 291
292 // Modification time is sent as string in a format: 'mm/dd/yy hh:mm:ss'. 292 // Modification time is set to the archive in local time.
293 var mt = this.metadata_[entryId].modificationTime; 293 var utc = this.metadata_[entryId].modificationTime;
294 var formattedTime = (mt.getMonth() + 1) + '/' + mt.getDate() + '/' + 294 var modificationTime = utc.getTime() - (utc.getTimezoneOffset() * 60000);
295 mt.getFullYear() + ' ' + mt.getHours() + ':' +
296 mt.getMinutes() + ':' + mt.getSeconds();
297 295
298 var request = unpacker.request.createAddToArchiveRequest( 296 var request = unpacker.request.createAddToArchiveRequest(
299 this.compressorId_, entryId, fullPath, 297 this.compressorId_, entryId, fullPath,
300 this.metadata_[entryId].size, formattedTime, 298 this.metadata_[entryId].size, modificationTime,
301 this.entries_[entryId].isDirectory); 299 this.entries_[entryId].isDirectory);
302 this.naclModule_.postMessage(request); 300 this.naclModule_.postMessage(request);
303 } 301 }
304 302
305 /** 303 /**
306 * Sends a close archive request to libarchive. libarchive writes metadata of 304 * Sends a close archive request to libarchive. libarchive writes metadata of
307 * the archive itself on the archive and releases objects obtainted in the 305 * the archive itself on the archive and releases objects obtainted in the
308 * packing process. 306 * packing process.
309 */ 307 */
310 unpacker.Compressor.prototype.sendCloseArchiveRequest = function(hasError) { 308 unpacker.Compressor.prototype.sendCloseArchiveRequest = function(hasError) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 readFileChunk(); 386 readFileChunk();
389 } 387 }
390 388
391 /** 389 /**
392 * A handler of write chunk requests. 390 * A handler of write chunk requests.
393 * Writes the data in the given buffer onto the archive file. 391 * Writes the data in the given buffer onto the archive file.
394 * @param {!Object} data 392 * @param {!Object} data
395 * @private 393 * @private
396 */ 394 */
397 unpacker.Compressor.prototype.onWriteChunk_ = function(data) { 395 unpacker.Compressor.prototype.onWriteChunk_ = function(data) {
396 var offset = Number(data[unpacker.request.Key.OFFSET]);
398 var length = Number(data[unpacker.request.Key.LENGTH]); 397 var length = Number(data[unpacker.request.Key.LENGTH]);
399 var buffer = data[unpacker.request.Key.CHUNK_BUFFER]; 398 var buffer = data[unpacker.request.Key.CHUNK_BUFFER];
400 this.writeChunk_(length, buffer, this.sendWriteChunkDone_.bind(this)); 399 this.writeChunk_(offset, length, buffer, this.sendWriteChunkDone_.bind(this));
401 } 400 }
402 401
403 /** 402 /**
404 * Writes buffer into the archive file (window.archiveFileEntry). 403 * Writes buffer into the archive file (window.archiveFileEntry).
404 * @param {number} offset The offset from which date is written.
405 * @param {number} length The number of bytes in the buffer to write. 405 * @param {number} length The number of bytes in the buffer to write.
406 * @param {!ArrayBuffer} buffer The buffer to write in the archive. 406 * @param {!ArrayBuffer} buffer The buffer to write in the archive.
407 * @param {function(number)} callback Callback to execute at the end of the 407 * @param {function(number)} callback Callback to execute at the end of the
408 * function. This function has one parameter: length, which represents the 408 * function. This function has one parameter: length, which represents the
409 * length of bytes written on to the archive. If writing a chunk fails, 409 * length of bytes written on to the archive. If writing a chunk fails,
410 * a negative value must be assigned to this argument. 410 * a negative value must be assigned to this argument.
411 * @private 411 * @private
412 */ 412 */
413 unpacker.Compressor.prototype.writeChunk_ = function(length, buffer, 413 unpacker.Compressor.prototype.writeChunk_ = function(offset, length, buffer,
414 callback) { 414 callback) {
415 // TODO(takise): Use the same instance of FileWriter over multiple calls of 415 // TODO(takise): Use the same instance of FileWriter over multiple calls of
416 // this function instead of creating new ones. 416 // this function instead of creating new ones.
417 this.archiveFileEntry_.createWriter(function(fileWriter) { 417 this.archiveFileEntry_.createWriter(function(fileWriter) {
418 fileWriter.onwriteend = function(event) { 418 fileWriter.onwriteend = function(event) {
419 callback(length); 419 callback(length);
420 }; 420 };
421 421
422 fileWriter.onerror = function(event) { 422 fileWriter.onerror = function(event) {
423 console.error('Failed to write chunk to ' + this.archiveFileEntry_ + '.'); 423 console.error('Failed to write chunk to ' + this.archiveFileEntry_ + '.');
424 424
425 // If the first argument(length) is negative, it means that an error 425 // If the first argument(length) is negative, it means that an error
426 // occurred in writing a chunk. 426 // occurred in writing a chunk.
427 callback(-1 /* length */); 427 callback(-1 /* length */);
428 this.onError_(this.compressorId_); 428 this.onError_(this.compressorId_);
429 }; 429 };
430 430
431 // Create a new Blob and append it to the archive file. 431 // Create a new Blob and append it to the archive file.
432 var blob = new Blob([buffer], {}); 432 var blob = new Blob([buffer], {});
433 fileWriter.seek(fileWriter.length); 433 fileWriter.seek(offset);
434 fileWriter.write(blob); 434 fileWriter.write(blob);
435 }, function(event) { 435 }, function(event) {
436 console.error('Failed to create writer for ' + this.archiveFileEntry_ + 436 console.error('Failed to create writer for ' + this.archiveFileEntry_ +
437 '.'); 437 '.');
438 this.onError_(this.compressorId_); 438 this.onError_(this.compressorId_);
439 }); 439 });
440 }; 440 };
441 441
442 /** 442 /**
443 * Sends a write chunk done response. 443 * Sends a write chunk done response.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 ': ' + data[unpacker.request.Key.ERROR]); // The error contains 507 ': ' + data[unpacker.request.Key.ERROR]); // The error contains
508 // the '.' at the end. 508 // the '.' at the end.
509 this.onError_(this.compressorId_); 509 this.onError_(this.compressorId_);
510 break; 510 break;
511 511
512 default: 512 default:
513 console.error('Invalid NaCl operation: ' + operation + '.'); 513 console.error('Invalid NaCl operation: ' + operation + '.');
514 this.onError_(this.compressorId_); 514 this.onError_(this.compressorId_);
515 } 515 }
516 }; 516 };
OLDNEW
« no previous file with comments | « ui/file_manager/zip_archiver/js/background.js ('k') | ui/file_manager/zip_archiver/js/passphrase-dialog.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698