mspack_rb 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/mspack.rb +4 -2
- data/lib/mspack/chm_decompressor.rb +50 -8
- data/lib/mspack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9daf394641a92e19fb3e05d7d07fc13b98607977
|
4
|
+
data.tar.gz: 2a3461a1586e09e9a779c665986352b545de8598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45d9c9d9776f80b19ea98344154759bed54a5929041e62f9dfac6894aa2358a6cf4a16bc20bbfdc7a511b9b203672272ba79deabe62cb6a640045c93d4744c07
|
7
|
+
data.tar.gz: 722d93e39669963796218d09aa47eab15bfe3bb3ef677617d8061119f16c0b87d3a1c9555b1e87bd9481204059f9143bd566fde60e8c0ecc61ea97a44a8810e0
|
data/Rakefile
CHANGED
data/lib/mspack.rb
CHANGED
@@ -2,19 +2,61 @@ require 'fileutils'
|
|
2
2
|
|
3
3
|
module Mspack
|
4
4
|
class ChmDecompressor
|
5
|
+
DEFAULT_BUFFER_SIZE = 4096.freeze
|
6
|
+
|
7
|
+
# Expects a ChmDecompressor::File and either a string, or a fixnum if a block
|
8
|
+
# is given.
|
9
|
+
#
|
10
|
+
# If no block is given, it calls Mspack.ensure_path and extracts file,
|
11
|
+
# returning the absolute file path.
|
12
|
+
#
|
13
|
+
# If a block is given, chunks of data are yielded with a maximum size given
|
14
|
+
# by the dir_or_buffer_size param. Buffer_size must be a multiple of
|
15
|
+
# DEFAULT_BUFFER_SIZE.
|
16
|
+
def extract(file, dir_or_buffer_size = DEFAULT_BUFFER_SIZE)
|
5
17
|
|
6
|
-
# Expects a ChmDecompressor::File and a string.
|
7
|
-
# Calls Mspack.ensure_path and extracts file.
|
8
|
-
# Returns the absolute file path.
|
9
|
-
def extract(file, dir = nil)
|
10
18
|
if block_given?
|
11
|
-
|
19
|
+
buffer_size = dir_or_buffer_size
|
20
|
+
|
21
|
+
if (buffer_size.fdiv(DEFAULT_BUFFER_SIZE).modulo(1) != 0)
|
22
|
+
raise ArgumentError,
|
23
|
+
'Buffer_size must be a multiple of DEFAULT_BUFFER_SIZE'
|
24
|
+
end
|
25
|
+
|
26
|
+
a = 0
|
27
|
+
b = 0
|
28
|
+
did_yield = false
|
29
|
+
buffer = "\0" * buffer_size
|
30
|
+
|
31
|
+
extract_to_path(file) do |data|
|
32
|
+
did_yield = false
|
33
|
+
b = a + data.length - 1
|
34
|
+
buffer[a..b] = data
|
35
|
+
|
36
|
+
# full buffer - yield and reset
|
37
|
+
if b + 1 == buffer_size
|
38
|
+
yield buffer[0..b]
|
39
|
+
did_yield = true
|
40
|
+
a = 0
|
41
|
+
|
42
|
+
# last read if it's less than default size
|
43
|
+
elsif data.length > 0 && data.length < DEFAULT_BUFFER_SIZE
|
44
|
+
yield buffer[0..b]
|
45
|
+
did_yield = true
|
46
|
+
|
47
|
+
else
|
48
|
+
a = b + 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# last read happened to be default size
|
53
|
+
yield buffer[0..b] if !did_yield && b > 0
|
54
|
+
|
12
55
|
else
|
13
|
-
path = Mspack.ensure_path(file.filename,
|
56
|
+
path = Mspack.ensure_path(file.filename, dir_or_buffer_size)
|
14
57
|
extract_to_path(file, path)
|
58
|
+
return path
|
15
59
|
end
|
16
|
-
|
17
|
-
path
|
18
60
|
end
|
19
61
|
|
20
62
|
|
data/lib/mspack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mspack_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|