michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const DATA = ""; michael@0: const FILENAME = "test.txt"; michael@0: const CRC = 0x00000000; michael@0: const time = Date.now(); michael@0: michael@0: function testpass(source) michael@0: { michael@0: // Should exist. michael@0: do_check_true(source.hasEntry(FILENAME)); michael@0: michael@0: var entry = source.getEntry(FILENAME); michael@0: do_check_neq(entry, null); michael@0: michael@0: do_check_false(entry.isDirectory); michael@0: michael@0: // Should be stored michael@0: do_check_eq(entry.compression, ZIP_METHOD_DEFLATE); michael@0: michael@0: // File size should match our data size. michael@0: do_check_eq(entry.realSize, DATA.length); michael@0: michael@0: // Check that the CRC is accurate michael@0: do_check_eq(entry.CRC32, CRC); michael@0: } michael@0: michael@0: function run_test() michael@0: { michael@0: zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); michael@0: michael@0: // Shouldn't be there to start with. michael@0: do_check_false(zipW.hasEntry(FILENAME)); michael@0: michael@0: do_check_false(zipW.inQueue); michael@0: michael@0: var file = do_get_file(DATA_DIR + "emptyfile.txt"); michael@0: zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false); michael@0: michael@0: // Check that zip state is right at this stage. michael@0: testpass(zipW); michael@0: zipW.close(); michael@0: michael@0: // Check to see if we get the same results loading afresh. michael@0: zipW.open(tmpFile, PR_RDWR); michael@0: testpass(zipW); michael@0: zipW.close(); michael@0: michael@0: // Test the stored data with the zipreader michael@0: var zipR = new ZipReader(tmpFile); michael@0: testpass(zipR); michael@0: zipR.test(FILENAME); michael@0: var stream = Cc["@mozilla.org/scriptableinputstream;1"] michael@0: .createInstance(Ci.nsIScriptableInputStream); michael@0: stream.init(zipR.getInputStream(FILENAME)); michael@0: var result = stream.read(DATA.length); michael@0: stream.close(); michael@0: zipR.close(); michael@0: michael@0: do_check_eq(result, DATA); michael@0: }