Module: Mspack

Defined in:
lib/mspack.rb,
lib/mspack/version.rb,
lib/mspack/chm_decompressor.rb,
ext/mspack_native/mspack_native.c

Defined Under Namespace

Classes: ChmDecompressor, PathError

Constant Summary collapse

VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.ensure_path(filename, dir) ⇒ Object

Expects two strings. Raises an error if dir is not an existing, writable directory. Expands the dir path, so you can use ~ and . etc. Creates non-existing parent folders for file.filename. Raises an error if the final, expanded path is outside of dir. Returns the expanded file path.

Raises:



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mspack.rb', line 16

def self.ensure_path(filename, dir)
  unless filename.is_a?(String) && dir.is_a?(String)
    raise TypeError, 'both parameters must be strings'
  end

  raise PathError, "#{dir} is not a directory" unless ::File.directory?(dir)
  raise PathError, "#{dir} is not writable" unless ::File.writable?(dir)

  expanded_dir = ::File.expand_path(dir)
  path = ::File.expand_path(::File.join(dir, filename))

  unless path.include?(expanded_dir)
    raise PathError, 
      "Expanded path #{path} is not within dir #{expanded_dir}"
  end

  FileUtils.mkdir_p(File.dirname(path))
  path
end

.testObject



13
14
15
16
17
# File 'ext/mspack_native/mspack_native.c', line 13

VALUE mspack_test() {
  int result;
  MSPACK_SYS_SELFTEST(result);
  return result == MSPACK_ERR_OK ? Qtrue : Qfalse;
}