packable 1.3.10 → 1.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.rdoc +4 -3
- data/lib/packable/extensions/io.rb +23 -4
- data/lib/packable/version.rb +1 -1
- data/packable.gemspec +2 -0
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418f5bd7ae865a2e8151c16e2916312e03abf93f49dce4bdc2f66ca9da4780fb
|
4
|
+
data.tar.gz: a1ed515518e37f91ce739252fa2fbd049521c882b20daccf5fc77e4d3a349f28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2fa7f4ed5881242241af1ba2606454c191ca3d6ab62f87ac7aac387920acaee28db40b9e6fa7ecbe6f92e8ab9c46f098dade847202269b9b80fbfd187d2cadd
|
7
|
+
data.tar.gz: 384ceca250f03b854c212376956e763655029719fe4c970ac8ef70749d1a8662f59230329b8994714fbdb25ed8932f79b918c4b72e610090090fe8bee5c53f3c
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
*Note*: SciRuby are taking over maintenance for this library: https://github.com/SciRuby/packable
|
2
|
-
|
3
1
|
= Packable Library - Intro
|
4
2
|
|
3
|
+
*NOTE:* This library monkeypatches core classes and wa designed for Ruby 1.8 & 1.9. A redesign using refinements would be much better. Minimal support is provided.
|
4
|
+
|
5
5
|
If you need to do read and write binary data, there is of course <tt>Array::pack</tt> and <tt>String::unpack</tt>.
|
6
6
|
The packable library makes (un)packing nicer, smarter and more powerful.
|
7
7
|
In case you are wondering why on earth someone would want to do serious (un)packing when YAML & XML are built-in:
|
@@ -26,6 +26,7 @@ The method +each+ also accepts packing options:
|
|
26
26
|
StringIO.new("\000\001\000\002\000\003").each(:short).to_a ===> [1,2,3]
|
27
27
|
=== Custom classes
|
28
28
|
It's easy to make you own classes (un)packable. All the previous goodies are thus available:
|
29
|
+
|
29
30
|
File.open("great_flick.flv") do |f|
|
30
31
|
head = f.read(FLV::Header)
|
31
32
|
f.each(FLV::Tag) do |tag|
|
@@ -97,7 +98,7 @@ When unpacking, it is necessary to specify the class in addition to any option,
|
|
97
98
|
|
98
99
|
It's easy to add shortcuts for easier (un)packing:
|
99
100
|
|
100
|
-
|
101
|
+
String.packers.set :flv_signature, :bytes => 3, :fill => "FLV"
|
101
102
|
|
102
103
|
"x".pack(:flv_signature) ===> "xFL"
|
103
104
|
|
@@ -10,6 +10,25 @@ module Packable
|
|
10
10
|
base.alias_method_chain :each, :packing
|
11
11
|
end
|
12
12
|
|
13
|
+
# Methods supported by seekable streams.
|
14
|
+
SEEKABLE_API = %i[pos pos= seek rewind].freeze
|
15
|
+
|
16
|
+
# Check whether can seek without errors.
|
17
|
+
def seekable?
|
18
|
+
if !defined?(@seekable)
|
19
|
+
@seekable =
|
20
|
+
# The IO class throws an exception at runtime if we try to change
|
21
|
+
# position on a non-regular file.
|
22
|
+
if respond_to?(:stat)
|
23
|
+
stat.file?
|
24
|
+
else
|
25
|
+
# Duck-type the rest of this.
|
26
|
+
SEEKABLE_API.all? { |m| respond_to?(m) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@seekable
|
30
|
+
end
|
31
|
+
|
13
32
|
# Returns the change in io.pos caused by the block.
|
14
33
|
# Has nothing to do with packing, but quite helpful and so simple...
|
15
34
|
def pos_change(&block)
|
@@ -53,17 +72,17 @@ module Packable
|
|
53
72
|
end
|
54
73
|
|
55
74
|
def each_with_packing(*options, &block)
|
56
|
-
return each_without_packing(*options, &block) if options.empty? || (Integer === options.first) || (String === options.first)
|
57
|
-
return
|
75
|
+
return each_without_packing(*options, &block) if options.empty? || (Integer === options.first) || (String === options.first) || !seekable?
|
76
|
+
return self.to_enum(__method__, *options) unless block_given?
|
58
77
|
yield read(*options) until eof?
|
59
78
|
end
|
60
79
|
|
61
80
|
def write_with_packing(*arg)
|
62
|
-
(arg.length <= 1) ? write_without_packing(*arg) : pack_and_write(*arg)
|
81
|
+
(arg.length <= 1 || !seekable?) ? write_without_packing(*arg) : pack_and_write(*arg)
|
63
82
|
end
|
64
83
|
|
65
84
|
def read_with_packing(*arg)
|
66
|
-
return read_without_packing(*arg) if arg.empty? || arg.first.nil? || arg.first.is_a?(Numeric)
|
85
|
+
return read_without_packing(*arg) if arg.empty? || arg.first.nil? || arg.first.is_a?(Numeric) || !seekable?
|
67
86
|
values = Packable::Packers.to_class_option_list(*arg).map do |klass, options, original|
|
68
87
|
if options[:read_packed]
|
69
88
|
options[:read_packed].call(self)
|
data/lib/packable/version.rb
CHANGED
data/packable.gemspec
CHANGED
@@ -6,6 +6,7 @@ require 'packable/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "packable"
|
8
8
|
gem.version = Packable::VERSION
|
9
|
+
gem.homepage = "https://github.com/marcandre/packable"
|
9
10
|
gem.authors = ["Marc-André Lafortune"]
|
10
11
|
gem.email = ["github@marc-andre.ca"]
|
11
12
|
gem.description = %q{If you need to do read and write binary data, there is of course <Array::pack and String::unpack\n The packable library makes (un)packing nicer, smarter and more powerful.\n}
|
@@ -16,6 +17,7 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
19
|
gem.require_paths = ["lib"]
|
20
|
+
gem.required_ruby_version = '>= 1.8.7'
|
19
21
|
gem.add_runtime_dependency 'backports'
|
20
22
|
gem.add_development_dependency 'minitest'
|
21
23
|
gem.add_development_dependency 'shoulda'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-André Lafortune
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backports
|
@@ -99,7 +99,7 @@ files:
|
|
99
99
|
homepage: ''
|
100
100
|
licenses: []
|
101
101
|
metadata: {}
|
102
|
-
post_install_message:
|
102
|
+
post_install_message:
|
103
103
|
rdoc_options: []
|
104
104
|
require_paths:
|
105
105
|
- lib
|
@@ -107,16 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 1.8.7
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
|
118
|
-
|
119
|
-
signing_key:
|
117
|
+
rubygems_version: 3.2.3
|
118
|
+
signing_key:
|
120
119
|
specification_version: 4
|
121
120
|
summary: Extensive packing and unpacking capabilities
|
122
121
|
test_files:
|