File: stored_support_test.rb

package info (click to toggle)
ruby-zip 2.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 1,192 kB
  • sloc: ruby: 8,386; makefile: 23
file content (34 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'test_helper'

class StoredSupportTest < MiniTest::Test
  STORED_ZIP_TEST_FILE = 'test/data/zipWithStoredCompression.zip'
  ENCRYPTED_STORED_ZIP_TEST_FILE = 'test/data/zipWithStoredCompressionAndEncryption.zip'
  INPUT_FILE1 = 'test/data/file1.txt'
  INPUT_FILE2 = 'test/data/file2.txt'

  def test_read
    Zip::InputStream.open(STORED_ZIP_TEST_FILE) do |zis|
      entry = zis.get_next_entry
      assert_equal 'file1.txt', entry.name
      assert_equal 1_327, entry.size
      assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read
      entry = zis.get_next_entry
      assert_equal 'file2.txt', entry.name
      assert_equal 41_234, entry.size
      assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read
    end
  end

  def test_encrypted_read
    Zip::InputStream.open(ENCRYPTED_STORED_ZIP_TEST_FILE, 0, Zip::TraditionalDecrypter.new('password')) do |zis|
      entry = zis.get_next_entry
      assert_equal 'file1.txt', entry.name
      assert_equal 1_327, entry.size
      assert_equal ::File.open(INPUT_FILE1, 'r').read, zis.read
      entry = zis.get_next_entry
      assert_equal 'file2.txt', entry.name
      assert_equal 41_234, entry.size
      assert_equal ::File.open(INPUT_FILE2, 'r').read, zis.read
    end
  end
end