msgpack 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ca0c3abd8883f5ba34b519986e789b6e029505a
4
- data.tar.gz: 2d8db1bcaeccbccebe206b99cdd361e7c32621a9
3
+ metadata.gz: 3b10edb0e5314270ccc2fb9f8f36c6496ff26a92
4
+ data.tar.gz: 0258a0e56bc3ba4f052d2ce45cda0bd2e24dc1c6
5
5
  SHA512:
6
- metadata.gz: f1adc454c670e6cb401bf103f389b0d3cff36f644bb1eeb57a2795c6757718a9124cb09c71a56a38e4a22345aec4a1f18178e45407fa5528566e762abaf3dc48
7
- data.tar.gz: 820785bf3360304db2d1011d108fbc167a827c07b43b3a17f0f9c6359a734aa6572f01c72946af6f6be923266c3d0e47e148009f557875cf66ecf8ce57f47a3c
6
+ metadata.gz: 24c445326d2c6b8cf769969ce02b9dd56c6ff4336794e41bce41a7c8fe9448037bb48ce2a8c5bb5595e3522dc23a5dd351788d738959935b7302e7d2c652b178
7
+ data.tar.gz: 06dddef0dc53502d70810e869e0ff9bc01976aca014d8530a11e724e4ef0e5ab9c3800c5e990419dce264fe8513b7ed46d63405db2f34ce8af0f2031084921eb
data/.travis.yml CHANGED
@@ -5,7 +5,6 @@ rvm:
5
5
  - 2.1.6
6
6
  - 2.2.2
7
7
  - ruby-head
8
- - rbx-2
9
8
  - jruby-19mode
10
9
  - jruby-head
11
10
 
@@ -28,3 +27,4 @@ matrix:
28
27
  - rvm: jruby-head
29
28
  - rvm: jruby-19mode
30
29
  os: osx
30
+ - rvm: rbx-2
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2016-01-06 version 0.7.2:
2
+
3
+ * Improved compatibility of Unpacker between CRuby and JRuby to accept stream-like object
4
+ by checking respond_to(:read) in addition to class check
5
+
1
6
  2015-11-20 version 0.7.1:
2
7
 
3
8
  * Fixed bug to pack/unpack ext type objects larger than 256bytes incorrectly.
data/Rakefile CHANGED
@@ -37,14 +37,6 @@ if RUBY_PLATFORM =~ /java/
37
37
  ext.source_version = '1.6'
38
38
  ext.target_version = '1.6'
39
39
  end
40
-
41
- RSpec::Core::RakeTask.new(:spec) do |t|
42
- t.rspec_opts = ["-c", "-f progress"]
43
- t.rspec_opts << "-Ilib"
44
- t.pattern = 'spec/{,jruby/}*_spec.rb'
45
- t.verbose = true
46
- end
47
-
48
40
  else
49
41
  require 'rake/extensiontask'
50
42
 
@@ -55,13 +47,18 @@ else
55
47
  # cross_platform names are of MRI's platform name
56
48
  ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
57
49
  end
50
+ end
58
51
 
59
- RSpec::Core::RakeTask.new(:spec) do |t|
60
- t.rspec_opts = ["-c", "-f progress"]
61
- t.rspec_opts << "-Ilib"
62
- t.pattern = 'spec/{,cruby/}*_spec.rb'
63
- t.verbose = true
64
- end
52
+ test_pattern = case
53
+ when RUBY_PLATFORM =~ /java/ then 'spec/{,jruby/}*_spec.rb'
54
+ when RUBY_ENGINE =~ /rbx/ then 'spec/*_spec.rb'
55
+ else 'spec/{,cruby/}*_spec.rb' # MRI
56
+ end
57
+ RSpec::Core::RakeTask.new(:spec) do |t|
58
+ t.rspec_opts = ["-c", "-f progress"]
59
+ t.rspec_opts << "-Ilib"
60
+ t.pattern = test_pattern
61
+ t.verbose = true
65
62
  end
66
63
 
67
64
  namespace :build do
@@ -297,6 +297,8 @@ public class Unpacker extends RubyObject {
297
297
  str = stream.callMethod(ctx, "string").asString();
298
298
  } else if (stream instanceof RubyIO) {
299
299
  str = stream.callMethod(ctx, "read").asString();
300
+ } else if (stream.respondsTo("read")) {
301
+ str = stream.callMethod(ctx, "read").asString();
300
302
  } else {
301
303
  throw ctx.getRuntime().newTypeError(stream, "IO");
302
304
  }
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.2"
3
3
  end
data/spec/packer_spec.rb CHANGED
@@ -2,6 +2,9 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  require 'stringio'
5
+ require 'tempfile'
6
+ require 'zlib'
7
+
5
8
  if defined?(Encoding)
6
9
  Encoding.default_external = 'ASCII-8BIT'
7
10
  end
@@ -19,6 +22,80 @@ describe MessagePack::Packer do
19
22
  MessagePack::Packer.new(StringIO.new, {})
20
23
  end
21
24
 
25
+ it 'gets IO or object which has #write to write/append data to it' do
26
+ sample_data = {"message" => "morning!", "num" => 1}
27
+ sample_packed = MessagePack.pack(sample_data)
28
+
29
+ Tempfile.open("for_io") do |file|
30
+ file.sync = true
31
+ p1 = MessagePack::Packer.new(file)
32
+ p1.write sample_data
33
+ p1.flush
34
+
35
+ file.rewind
36
+ expect(file.read).to eql(sample_packed)
37
+ file.unlink
38
+ end
39
+
40
+ dio = StringIO.new
41
+ p2 = MessagePack::Packer.new(dio)
42
+ p2.write sample_data
43
+ p2.flush
44
+ dio.rewind
45
+ expect(dio.string).to eql(sample_packed)
46
+
47
+ unless defined? JRUBY_VERSION
48
+ # JRuby seems to have bug not to flush GzipWriter buffer correctly (both of 1.7 and 9.0)
49
+ dio = StringIO.new
50
+ writer = Zlib::GzipWriter.new(dio)
51
+ writer.sync = true
52
+ p3 = MessagePack::Packer.new(writer)
53
+ p3.write sample_data
54
+ p3.flush
55
+ writer.flush(Zlib::FINISH)
56
+ writer.close
57
+ dio.rewind
58
+ compressed = dio.string
59
+ str = Zlib::GzipReader.wrap(StringIO.new(compressed)){|gz| gz.read }
60
+ expect(str).to eql(sample_packed)
61
+ end
62
+
63
+ class DummyIO
64
+ def initialize
65
+ @buf = "".force_encoding('ASCII-8BIT')
66
+ @pos = 0
67
+ end
68
+ def write(val)
69
+ @buf << val.to_s
70
+ end
71
+ def read(length=nil,outbuf="")
72
+ if @pos == @buf.size
73
+ nil
74
+ elsif length.nil?
75
+ val = @buf[@pos..(@buf.size)]
76
+ @pos = @buf.size
77
+ outbuf << val
78
+ outbuf
79
+ else
80
+ val = @buf[@pos..(@pos + length)]
81
+ @pos += val.size
82
+ @pos = @buf.size if @pos > @buf.size
83
+ outbuf << val
84
+ outbuf
85
+ end
86
+ end
87
+ def flush
88
+ # nop
89
+ end
90
+ end
91
+
92
+ dio = DummyIO.new
93
+ p4 = MessagePack::Packer.new(dio)
94
+ p4.write sample_data
95
+ p4.flush
96
+ expect(dio.read).to eql(sample_packed)
97
+ end
98
+
22
99
  it 'gets options to specify how to pack values' do
23
100
  u1 = MessagePack::Packer.new
24
101
  u1.compatibility_mode?.should == false
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
+ require 'zlib'
5
6
 
6
7
  require 'spec_helper'
7
8
 
@@ -24,6 +25,73 @@ describe MessagePack::Unpacker do
24
25
  u2.allow_unknown_ext?.should == true
25
26
  end
26
27
 
28
+ it 'gets IO or object which has #read to read data from it' do
29
+ sample_data = {"message" => "morning!", "num" => 1}
30
+ sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
31
+
32
+ Tempfile.open("for_io") do |file|
33
+ file.sync = true
34
+ file.write sample_packed
35
+ file.rewind
36
+
37
+ u1 = MessagePack::Unpacker.new(file)
38
+ u1.each do |obj|
39
+ expect(obj).to eql(sample_data)
40
+ end
41
+ file.unlink
42
+ end
43
+
44
+ sio = StringIO.new(sample_packed)
45
+ u2 = MessagePack::Unpacker.new(sio)
46
+ u2.each do |obj|
47
+ expect(obj).to eql(sample_data)
48
+ end
49
+
50
+ dio = StringIO.new
51
+ Zlib::GzipWriter.wrap(dio){|gz| gz.write sample_packed }
52
+ reader = Zlib::GzipReader.new(StringIO.new(dio.string))
53
+ u3 = MessagePack::Unpacker.new(reader)
54
+ u3.each do |obj|
55
+ expect(obj).to eql(sample_data)
56
+ end
57
+
58
+ class DummyIO
59
+ def initialize
60
+ @buf = "".force_encoding('ASCII-8BIT')
61
+ @pos = 0
62
+ end
63
+ def write(val)
64
+ @buf << val.to_s
65
+ end
66
+ def read(length=nil,outbuf="")
67
+ if @pos == @buf.size
68
+ nil
69
+ elsif length.nil?
70
+ val = @buf[@pos..(@buf.size)]
71
+ @pos = @buf.size
72
+ outbuf << val
73
+ outbuf
74
+ else
75
+ val = @buf[@pos..(@pos + length)]
76
+ @pos += val.size
77
+ @pos = @buf.size if @pos > @buf.size
78
+ outbuf << val
79
+ outbuf
80
+ end
81
+ end
82
+ def flush
83
+ # nop
84
+ end
85
+ end
86
+
87
+ dio = DummyIO.new
88
+ dio.write sample_packed
89
+ u4 = MessagePack::Unpacker.new(dio)
90
+ u4.each do |obj|
91
+ expect(obj).to eql(sample_data)
92
+ end
93
+ end
94
+
27
95
  it 'read_array_header succeeds' do
28
96
  unpacker.feed("\x91")
29
97
  unpacker.read_array_header.should == 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-20 00:00:00.000000000 Z
13
+ date: 2016-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler