mspack_rb 0.1.4 → 0.1.5
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.md +1 -9
- data/lib/mspack/chm_decompressor.rb +8 -2
- data/lib/mspack/version.rb +1 -1
- data/lib/mspack.rb +29 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c69d841d0a58a91453d2b8ebd9f3a91030b67c64
|
4
|
+
data.tar.gz: c087616dcf7d380e2c635f9e07d056b77c632c85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86224b683f84c19b88445c65587d9cbca548a20e398b0681f1fb9fecf2d4467f4711abcb410b4c85cc4eec42895f28ba229425a4ff5d8a0052258be199385a03
|
7
|
+
data.tar.gz: 67bba4649f8e0be72c7fbe2791e35c65f3ffcd8321d69564639ef358335e7a31363c0ce71fed9fe98ff1281ff6fbbc23f21b4d166a1bb2839b42b8f54774d7cc
|
data/README.md
CHANGED
@@ -10,14 +10,6 @@ The gem is available over at [https://rubygems.org/gems/mspack_rb](https://rubyg
|
|
10
10
|
### Usage:
|
11
11
|
require 'mspack'
|
12
12
|
|
13
|
-
OUT_DIR = 'some/output/directory'
|
14
|
-
|
15
13
|
dcom = Mspack::ChmDecompressor.new
|
16
14
|
header = dcom.open('path/to/a/chm/file')
|
17
|
-
|
18
|
-
header.each_file do |file|
|
19
|
-
out_path = "#{OUT_DIR}/#{file.filename}"
|
20
|
-
dcom.extract(file, out_path)
|
21
|
-
end
|
22
|
-
|
23
|
-
dcom.close(header)
|
15
|
+
header.each_file { |file| dcom.extract(file, out_path) }
|
@@ -1,9 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
module Mspack
|
2
4
|
class ChmDecompressor
|
3
5
|
|
4
|
-
|
6
|
+
# Expects a ChmDecompressor::File and a string.
|
7
|
+
# Calls Mspack.ensure_path and extracts file.
|
8
|
+
# Returns the absolute file path.
|
5
9
|
def extract(file, dir)
|
6
|
-
|
10
|
+
path = Mspack.ensure_path(file.filename, dir)
|
11
|
+
extract_to_path(file, path)
|
12
|
+
path
|
7
13
|
end
|
8
14
|
|
9
15
|
|
data/lib/mspack/version.rb
CHANGED
data/lib/mspack.rb
CHANGED
@@ -2,3 +2,32 @@ require "mspack_native"
|
|
2
2
|
|
3
3
|
require "mspack/chm_decompressor"
|
4
4
|
require "mspack/version"
|
5
|
+
|
6
|
+
module Mspack
|
7
|
+
|
8
|
+
# Expects two strings.
|
9
|
+
# Raises an error if dir is not an existing, writable directory.
|
10
|
+
# Expands the dir path, so you can use ~ and . etc.
|
11
|
+
# Creates non-existing parent folders for file.filename.
|
12
|
+
# Raises an error if the final, expanded path is outside of dir.
|
13
|
+
# Returns the expanded file path.
|
14
|
+
def self.ensure_path(filename, dir)
|
15
|
+
raise PathError, "#{dir} is not a directory" unless ::File.directory?(dir)
|
16
|
+
raise PathError, "#{dir} is not writable" unless ::File.writable?(dir)
|
17
|
+
|
18
|
+
expanded_dir = ::File.expand_path(dir)
|
19
|
+
path = ::File.expand_path(::File.join(dir, filename))
|
20
|
+
|
21
|
+
unless path.include?(expanded_dir)
|
22
|
+
raise PathError,
|
23
|
+
"Expanded path #{path} is not within dir #{expanded_dir}"
|
24
|
+
end
|
25
|
+
|
26
|
+
FileUtils.mkdir_p(File.dirname(path))
|
27
|
+
path
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class PathError < StandardError
|
32
|
+
end
|
33
|
+
end
|