iostreams 1.10.2 → 1.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/zip/writer.rb +6 -2
- data/test/bzip2_writer_test.rb +14 -8
- data/test/encode_writer_test.rb +19 -10
- data/test/gzip_writer_test.rb +16 -8
- data/test/line_writer_test.rb +19 -9
- data/test/pgp_writer_test.rb +18 -9
- data/test/record_writer_test.rb +20 -10
- data/test/row_writer_test.rb +13 -7
- data/test/zip_writer_test.rb +13 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ace4685022c88754654b2b48d1c86185e47841f1d3c6a3916bc348098b178d
|
4
|
+
data.tar.gz: 040c669d7ad4521941a3752dc405390c4f7dda98a583cc0f5d923091e12bd452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90f2635d2e443fe4c4f3992d8f92a725118b2f52c0d4861ee1d778be8f145d93c2f0663904f8cf699b33106a154d13980634881a0039c7e0ad6389d137d69760
|
7
|
+
data.tar.gz: 970da1fd8e3b6ea7e1b36dad476c7f842413c2b8b50dc2939802b1962c00347bcdfa6a135245550c9cb639b694e9ca2c16439bde1afe7677701f3867cdc277e4
|
data/lib/io_streams/version.rb
CHANGED
@@ -14,7 +14,7 @@ module IOStreams
|
|
14
14
|
# Name of the file entry within the Zip file.
|
15
15
|
#
|
16
16
|
# The stream supplied to the block only responds to #write
|
17
|
-
def self.stream(output_stream, original_file_name: nil, zip_file_name: nil, entry_file_name: zip_file_name
|
17
|
+
def self.stream(output_stream, original_file_name: nil, zip_file_name: nil, entry_file_name: zip_file_name)
|
18
18
|
# Default the name of the file within the zip to the supplied file_name without the zip extension
|
19
19
|
if entry_file_name.nil? && original_file_name && (original_file_name =~ /\.(zip)\z/i)
|
20
20
|
entry_file_name = original_file_name.to_s[0..-5]
|
@@ -23,7 +23,11 @@ module IOStreams
|
|
23
23
|
|
24
24
|
Utils.load_soft_dependency("zip_tricks", "Zip") unless defined?(ZipTricks::Streamer)
|
25
25
|
|
26
|
-
|
26
|
+
result = nil
|
27
|
+
ZipTricks::Streamer.open(output_stream) do |zip|
|
28
|
+
zip.write_deflated_file(entry_file_name) { |io| result = yield(io) }
|
29
|
+
end
|
30
|
+
result
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/test/bzip2_writer_test.rb
CHANGED
@@ -20,10 +20,13 @@ class Bzip2WriterTest < Minitest::Test
|
|
20
20
|
|
21
21
|
describe ".file" do
|
22
22
|
it "file" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
result =
|
24
|
+
IOStreams::Bzip2::Writer.file(file_name) do |io|
|
25
|
+
io.write(decompressed)
|
26
|
+
io.write(decompressed)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
|
28
31
|
File.open(file_name, "rb") do |file|
|
29
32
|
io = ::Bzip2::FFI::Reader.new(file)
|
@@ -35,10 +38,13 @@ class Bzip2WriterTest < Minitest::Test
|
|
35
38
|
|
36
39
|
it "stream" do
|
37
40
|
io_string = StringIO.new("".b)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
result =
|
42
|
+
IOStreams::Bzip2::Writer.stream(io_string) do |io|
|
43
|
+
io.write(decompressed)
|
44
|
+
io.write(decompressed)
|
45
|
+
53534
|
46
|
+
end
|
47
|
+
assert_equal 53534, result
|
42
48
|
|
43
49
|
io = StringIO.new(io_string.string)
|
44
50
|
rbzip2 = ::Bzip2::FFI::Reader.new(io)
|
data/test/encode_writer_test.rb
CHANGED
@@ -22,18 +22,24 @@ class EncodeWriterTest < Minitest::Test
|
|
22
22
|
it "file" do
|
23
23
|
temp_file = Tempfile.new("rocket_job")
|
24
24
|
file_name = temp_file.to_path
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
result =
|
26
|
+
IOStreams::Encode::Writer.file(file_name, encoding: "ASCII-8BIT") do |io|
|
27
|
+
io << bad_data
|
28
|
+
53534
|
29
|
+
end
|
30
|
+
assert_equal 53534, result
|
28
31
|
result = File.read(file_name, mode: "rb")
|
29
32
|
assert_equal bad_data, result
|
30
33
|
end
|
31
34
|
|
32
35
|
it "stream" do
|
33
|
-
io
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
io = StringIO.new("".b)
|
37
|
+
result =
|
38
|
+
IOStreams::Encode::Writer.stream(io, encoding: "ASCII-8BIT") do |encoded|
|
39
|
+
encoded << bad_data
|
40
|
+
53534
|
41
|
+
end
|
42
|
+
assert_equal 53534, result
|
37
43
|
assert_equal "ASCII-8BIT", io.string.encoding.to_s
|
38
44
|
assert_equal bad_data, io.string
|
39
45
|
end
|
@@ -70,9 +76,12 @@ class EncodeWriterTest < Minitest::Test
|
|
70
76
|
it "returns byte count" do
|
71
77
|
io_string = StringIO.new("".b)
|
72
78
|
count = 0
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
result =
|
80
|
+
IOStreams::Encode::Writer.stream(io_string, encoding: "ASCII-8BIT") do |io|
|
81
|
+
count += io.write(bad_data)
|
82
|
+
53534
|
83
|
+
end
|
84
|
+
assert_equal 53534, result
|
76
85
|
assert_equal bad_data, io_string.string
|
77
86
|
assert_equal bad_data.size, count
|
78
87
|
end
|
data/test/gzip_writer_test.rb
CHANGED
@@ -20,9 +20,13 @@ class GzipWriterTest < Minitest::Test
|
|
20
20
|
|
21
21
|
describe ".file" do
|
22
22
|
it "file" do
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
result =
|
24
|
+
IOStreams::Gzip::Writer.file(file_name) do |io|
|
25
|
+
io.write(decompressed)
|
26
|
+
53534
|
27
|
+
end
|
28
|
+
assert_equal 53534, result
|
29
|
+
|
26
30
|
result = Zlib::GzipReader.open(file_name, &:read)
|
27
31
|
temp_file.delete
|
28
32
|
assert_equal decompressed, result
|
@@ -30,11 +34,15 @@ class GzipWriterTest < Minitest::Test
|
|
30
34
|
|
31
35
|
it "stream" do
|
32
36
|
io_string = StringIO.new("".b)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
result =
|
38
|
+
IOStreams::Gzip::Writer.stream(io_string) do |io|
|
39
|
+
io.write(decompressed)
|
40
|
+
53534
|
41
|
+
end
|
42
|
+
assert_equal 53534, result
|
43
|
+
|
44
|
+
io = StringIO.new(io_string.string)
|
45
|
+
gz = Zlib::GzipReader.new(io)
|
38
46
|
data = gz.read
|
39
47
|
gz.close
|
40
48
|
assert_equal decompressed, data
|
data/test/line_writer_test.rb
CHANGED
@@ -18,18 +18,25 @@ class DelimitedWriterTest < Minitest::Test
|
|
18
18
|
it "file" do
|
19
19
|
temp_file = Tempfile.new("rocket_job")
|
20
20
|
file_name = temp_file.to_path
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
result =
|
22
|
+
IOStreams::Line::Writer.file(file_name) do |io|
|
23
|
+
lines.each { |line| io << line }
|
24
|
+
53534
|
25
|
+
end
|
26
|
+
assert_equal 53534, result
|
27
|
+
|
24
28
|
result = File.read(file_name)
|
25
29
|
assert_equal raw, result
|
26
30
|
end
|
27
31
|
|
28
32
|
it "stream" do
|
29
33
|
io_string = StringIO.new
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
result =
|
35
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
36
|
+
lines.each { |line| io << line }
|
37
|
+
53534
|
38
|
+
end
|
39
|
+
assert_equal 53534, result
|
33
40
|
assert_equal raw, io_string.string
|
34
41
|
end
|
35
42
|
end
|
@@ -38,9 +45,12 @@ class DelimitedWriterTest < Minitest::Test
|
|
38
45
|
it "returns byte count" do
|
39
46
|
io_string = StringIO.new
|
40
47
|
count = 0
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
result =
|
49
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
50
|
+
lines.each { |line| count += io.write(line) }
|
51
|
+
53534
|
52
|
+
end
|
53
|
+
assert_equal 53534, result
|
44
54
|
assert_equal raw, io_string.string
|
45
55
|
assert_equal raw.size, count
|
46
56
|
end
|
data/test/pgp_writer_test.rb
CHANGED
@@ -21,9 +21,12 @@ class PgpWriterTest < Minitest::Test
|
|
21
21
|
|
22
22
|
describe ".file" do
|
23
23
|
it "writes encrypted text file" do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
result =
|
25
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: "receiver@example.org") do |io|
|
26
|
+
io.write(decrypted)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
|
28
31
|
result = IOStreams::Pgp::Reader.file(file_name, passphrase: "receiver_passphrase", &:read)
|
29
32
|
assert_equal decrypted, result
|
@@ -34,9 +37,12 @@ class PgpWriterTest < Minitest::Test
|
|
34
37
|
binary_data = File.open(binary_file_name, "rb", &:read)
|
35
38
|
|
36
39
|
File.open(binary_file_name, "rb") do |input|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
result =
|
41
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: "receiver@example.org") do |output|
|
42
|
+
IO.copy_stream(input, output)
|
43
|
+
53534
|
44
|
+
end
|
45
|
+
assert_equal 53534, result
|
40
46
|
end
|
41
47
|
|
42
48
|
result = IOStreams::Pgp::Reader.file(file_name, passphrase: "receiver_passphrase", &:read)
|
@@ -108,9 +114,12 @@ class PgpWriterTest < Minitest::Test
|
|
108
114
|
|
109
115
|
it "writes to a stream" do
|
110
116
|
io_string = StringIO.new("".b)
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
result =
|
118
|
+
IOStreams::Pgp::Writer.stream(io_string, recipient: "receiver@example.org", signer: "sender@example.org", signer_passphrase: "sender_passphrase") do |io|
|
119
|
+
io.write(decrypted)
|
120
|
+
53534
|
121
|
+
end
|
122
|
+
assert_equal 53534, result
|
114
123
|
|
115
124
|
io = StringIO.new(io_string.string)
|
116
125
|
result = IOStreams::Pgp::Reader.stream(io, passphrase: "receiver_passphrase", &:read)
|
data/test/record_writer_test.rb
CHANGED
@@ -43,28 +43,38 @@ class RecordWriterTest < Minitest::Test
|
|
43
43
|
|
44
44
|
describe "#<<" do
|
45
45
|
it "file" do
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
result =
|
47
|
+
IOStreams::Record::Writer.file(file_name) do |io|
|
48
|
+
inputs.each { |hash| io << hash }
|
49
|
+
53534
|
50
|
+
end
|
51
|
+
assert_equal 53534, result
|
49
52
|
result = File.read(file_name)
|
50
53
|
assert_equal raw_csv_data, result
|
51
54
|
end
|
52
55
|
|
53
56
|
it "json file" do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
result =
|
58
|
+
IOStreams::Record::Writer.file(file_name, file_name: "abc.json") do |io|
|
59
|
+
inputs.each { |hash| io << hash }
|
60
|
+
53534
|
61
|
+
end
|
62
|
+
assert_equal 53534, result
|
63
|
+
|
57
64
|
result = File.read(file_name)
|
58
65
|
assert_equal raw_json_data, result
|
59
66
|
end
|
60
67
|
|
61
68
|
it "stream" do
|
62
69
|
io_string = StringIO.new
|
63
|
-
|
64
|
-
IOStreams::
|
65
|
-
|
70
|
+
result =
|
71
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
72
|
+
IOStreams::Record::Writer.stream(io) do |stream|
|
73
|
+
inputs.each { |row| stream << row }
|
74
|
+
53534
|
75
|
+
end
|
66
76
|
end
|
67
|
-
|
77
|
+
assert_equal 53534, result
|
68
78
|
assert_equal raw_csv_data, io_string.string
|
69
79
|
end
|
70
80
|
end
|
data/test/row_writer_test.rb
CHANGED
@@ -29,20 +29,26 @@ class RowWriterTest < Minitest::Test
|
|
29
29
|
|
30
30
|
describe ".stream" do
|
31
31
|
it "file" do
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
result =
|
33
|
+
IOStreams::Row::Writer.file(file_name) do |io|
|
34
|
+
csv_rows.each { |array| io << array }
|
35
|
+
53534
|
36
|
+
end
|
37
|
+
assert_equal 53534, result
|
35
38
|
result = ::File.read(file_name)
|
36
39
|
assert_equal raw_csv_data, result
|
37
40
|
end
|
38
41
|
|
39
42
|
it "streams" do
|
40
43
|
io_string = StringIO.new
|
41
|
-
|
42
|
-
IOStreams::
|
43
|
-
|
44
|
+
result =
|
45
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
46
|
+
IOStreams::Row::Writer.stream(io) do |stream|
|
47
|
+
csv_rows.each { |array| stream << array }
|
48
|
+
53534
|
49
|
+
end
|
44
50
|
end
|
45
|
-
|
51
|
+
assert_equal 53534, result
|
46
52
|
assert_equal raw_csv_data, io_string.string
|
47
53
|
end
|
48
54
|
end
|
data/test/zip_writer_test.rb
CHANGED
@@ -21,19 +21,25 @@ class ZipWriterTest < Minitest::Test
|
|
21
21
|
|
22
22
|
describe ".file" do
|
23
23
|
it "file" do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
result =
|
25
|
+
IOStreams::Zip::Writer.file(file_name, entry_file_name: "text.txt") do |io|
|
26
|
+
io.write(decompressed)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
result = IOStreams::Zip::Reader.file(file_name, &:read)
|
28
31
|
assert_equal decompressed, result
|
29
32
|
end
|
30
33
|
|
31
34
|
it "stream" do
|
32
35
|
io_string = StringIO.new("".b)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
result =
|
37
|
+
IOStreams::Zip::Writer.stream(io_string) do |io|
|
38
|
+
io.write(decompressed)
|
39
|
+
53534
|
40
|
+
end
|
41
|
+
assert_equal 53534, result
|
42
|
+
io = StringIO.new(io_string.string)
|
37
43
|
result = IOStreams::Zip::Reader.stream(io, &:read)
|
38
44
|
assert_equal decompressed, result
|
39
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iostreams
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.10.
|
4
|
+
version: 1.10.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|