test_deflatedata.js (1611B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 const DATA = "ZIP WRITER TEST DATA"; 7 const FILENAME = "test.txt"; 8 const CRC = 0xe6164331; 9 // XXX Must use a constant time here away from DST changes. See bug 402434. 10 const time = 1199145600000; // Jan 1st 2008 11 12 function run_test() { 13 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); 14 15 // Shouldn't be there to start with. 16 Assert.ok(!zipW.hasEntry(FILENAME)); 17 18 Assert.ok(!zipW.inQueue); 19 20 var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance( 21 Ci.nsIStringInputStream 22 ); 23 stream.setByteStringData(DATA); 24 zipW.addEntryStream( 25 FILENAME, 26 time * PR_USEC_PER_MSEC, 27 Ci.nsIZipWriter.COMPRESSION_BEST, 28 stream, 29 false 30 ); 31 32 var entry = zipW.getEntry(FILENAME); 33 34 Assert.notEqual(entry, null); 35 36 // Check entry seems right. 37 Assert.equal(entry.compression, ZIP_METHOD_DEFLATE); 38 Assert.equal(entry.CRC32, CRC); 39 Assert.equal(entry.realSize, DATA.length); 40 Assert.equal(entry.lastModifiedTime / PR_USEC_PER_MSEC, time); 41 42 zipW.close(); 43 44 // Test the stored data with the zipreader 45 var zipR = new ZipReader(tmpFile); 46 Assert.ok(zipR.hasEntry(FILENAME)); 47 48 zipR.test(FILENAME); 49 50 stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance( 51 Ci.nsIScriptableInputStream 52 ); 53 stream.init(zipR.getInputStream(FILENAME)); 54 var result = stream.read(DATA.length); 55 stream.close(); 56 zipR.close(); 57 58 Assert.equal(result, DATA); 59 }