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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1568ae7d72717343ee02824b749cd95d4f753d52
4
- data.tar.gz: 2eb7e0c19332a52dc5fbee34041806319009ee45
3
+ metadata.gz: c69d841d0a58a91453d2b8ebd9f3a91030b67c64
4
+ data.tar.gz: c087616dcf7d380e2c635f9e07d056b77c632c85
5
5
  SHA512:
6
- metadata.gz: 23ad79da53211a12bedd97e9ced8516c2b39f795b9e417f0221871060164f7e62446953ddfebba690626f68d27d83169d0cfd4026633625f72f2b89aeeac88ac
7
- data.tar.gz: e4752a1bf9ff5e68a521fe5bcf858f71324b5fde7aedc8eb3dd963b095946904721be5c8a7cd0b4faa94b09b893d9afeb0855523e1403cabdfbf2b67db2ab980
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
 
@@ -1,3 +1,3 @@
1
1
  module Mspack
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspack_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Williams