mspack_rb 0.1.3 → 0.1.4
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 +7 -6
- data/ext/mspack_native/chm_decompressor.c +104 -0
- data/ext/mspack_native/chm_decompressor.h +12 -0
- data/ext/mspack_native/mspack_native.c +4 -98
- data/ext/mspack_native/mspack_native.h +8 -0
- data/lib/mspack/chm_decompressor.rb +8 -0
- data/lib/mspack/version.rb +1 -1
- data/lib/mspack.rb +1 -0
- data/lib/mspack_native.bundle +0 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1568ae7d72717343ee02824b749cd95d4f753d52
|
4
|
+
data.tar.gz: 2eb7e0c19332a52dc5fbee34041806319009ee45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ad79da53211a12bedd97e9ced8516c2b39f795b9e417f0221871060164f7e62446953ddfebba690626f68d27d83169d0cfd4026633625f72f2b89aeeac88ac
|
7
|
+
data.tar.gz: e4752a1bf9ff5e68a521fe5bcf858f71324b5fde7aedc8eb3dd963b095946904721be5c8a7cd0b4faa94b09b893d9afeb0855523e1403cabdfbf2b67db2ab980
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
### A simple Ruby native extension gem wrapper for [libmspack](https://www.cabextract.org.uk/libmspack/)
|
4
4
|
|
5
|
-
Requires libmspack to be installed, and currently, only
|
5
|
+
Requires libmspack to be installed, and currently, only basic CHM
|
6
6
|
extraction has been implemented.
|
7
7
|
|
8
8
|
The gem is available over at [https://rubygems.org/gems/mspack_rb](https://rubygems.org/gems/mspack_rb).
|
@@ -10,13 +10,14 @@ 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
|
+
|
13
15
|
dcom = Mspack::ChmDecompressor.new
|
14
16
|
header = dcom.open('path/to/a/chm/file')
|
15
|
-
file = header.files
|
16
|
-
out_dir = 'some/output/directory'
|
17
17
|
|
18
|
-
|
19
|
-
out_path = "#{
|
18
|
+
header.each_file do |file|
|
19
|
+
out_path = "#{OUT_DIR}/#{file.filename}"
|
20
20
|
dcom.extract(file, out_path)
|
21
|
-
file = file.next
|
22
21
|
end
|
22
|
+
|
23
|
+
dcom.close(header)
|
@@ -0,0 +1,104 @@
|
|
1
|
+
#include "chm_decompressor.h"
|
2
|
+
|
3
|
+
#include <mspack.h>
|
4
|
+
|
5
|
+
VALUE ChmDecom = Qnil;
|
6
|
+
VALUE ChmDHeader = Qnil;
|
7
|
+
VALUE ChmDFile = Qnil;
|
8
|
+
|
9
|
+
void chmd_deallocate(void *decom) {
|
10
|
+
mspack_destroy_chm_decompressor(decom);
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE chmd_allocate(VALUE self) {
|
14
|
+
struct mschm_decompressor *decom = mspack_create_chm_decompressor(NULL);
|
15
|
+
return Data_Wrap_Struct(self, NULL, chmd_deallocate, decom);
|
16
|
+
}
|
17
|
+
|
18
|
+
VALUE chmd_open(VALUE self, VALUE path) {
|
19
|
+
struct mschm_decompressor *decom;
|
20
|
+
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
21
|
+
struct mschmd_header *header = decom->open(decom, StringValueCStr(path));
|
22
|
+
|
23
|
+
if (!header) {
|
24
|
+
return Qnil;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE headerObj = rb_obj_alloc(ChmDHeader);
|
28
|
+
rb_obj_call_init(headerObj, 0, NULL);
|
29
|
+
return Data_Wrap_Struct(ChmDHeader, NULL, NULL, header);
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE chmd_close(VALUE self, VALUE header) {
|
33
|
+
struct mschm_decompressor *decom;
|
34
|
+
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
35
|
+
|
36
|
+
struct mschmd_header *headerPtr;
|
37
|
+
Data_Get_Struct(header, struct mschmd_header, headerPtr);
|
38
|
+
|
39
|
+
decom->close(decom, headerPtr);
|
40
|
+
return Qnil;
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE chmd_extract_to_path(VALUE self, VALUE file, VALUE outputPath) {
|
44
|
+
struct mschm_decompressor *decom;
|
45
|
+
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
46
|
+
|
47
|
+
struct mschmd_file *filePtr;
|
48
|
+
Data_Get_Struct(file, struct mschmd_file, filePtr);
|
49
|
+
|
50
|
+
const char *pathStr = StringValueCStr(outputPath);
|
51
|
+
return decom->extract(decom, filePtr, pathStr) == MSPACK_ERR_OK ?
|
52
|
+
Qtrue : Qfalse;
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE chmd_header_filename(VALUE self) {
|
56
|
+
struct mschmd_header *header;
|
57
|
+
Data_Get_Struct(self, struct mschmd_header, header);
|
58
|
+
return rb_str_new2(header->filename);
|
59
|
+
}
|
60
|
+
|
61
|
+
VALUE chmd_header_files(VALUE self) {
|
62
|
+
struct mschmd_header *header;
|
63
|
+
Data_Get_Struct(self, struct mschmd_header, header);
|
64
|
+
|
65
|
+
VALUE fileObj = rb_obj_alloc(ChmDFile);
|
66
|
+
rb_obj_call_init(fileObj, 0, NULL);
|
67
|
+
return Data_Wrap_Struct(ChmDFile, NULL, NULL, header->files);
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE chmd_file_filename(VALUE self) {
|
71
|
+
struct mschmd_file *file;
|
72
|
+
Data_Get_Struct(self, struct mschmd_file, file);
|
73
|
+
return rb_str_new2(file->filename);
|
74
|
+
}
|
75
|
+
|
76
|
+
VALUE chmd_file_next(VALUE self) {
|
77
|
+
struct mschmd_file *file;
|
78
|
+
Data_Get_Struct(self, struct mschmd_file, file);
|
79
|
+
struct mschmd_file *next = file->next;
|
80
|
+
|
81
|
+
if (next == NULL) {
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE nextObj = rb_obj_alloc(ChmDFile);
|
86
|
+
rb_obj_call_init(nextObj, 0, NULL);
|
87
|
+
return Data_Wrap_Struct(ChmDFile, NULL, NULL, next);
|
88
|
+
}
|
89
|
+
|
90
|
+
void Init_chm_decompressor() {
|
91
|
+
ChmDecom = rb_define_class_under(Mspack, "ChmDecompressor", rb_cObject);
|
92
|
+
rb_define_alloc_func(ChmDecom, chmd_allocate);
|
93
|
+
rb_define_method(ChmDecom, "open", chmd_open, 1);
|
94
|
+
rb_define_method(ChmDecom, "close", chmd_close, 1);
|
95
|
+
rb_define_method(ChmDecom, "extract_to_path", chmd_extract_to_path, 2);
|
96
|
+
|
97
|
+
ChmDHeader = rb_define_class_under(ChmDecom, "Header", rb_cObject);
|
98
|
+
rb_define_method(ChmDHeader, "filename", chmd_header_filename, 0);
|
99
|
+
rb_define_method(ChmDHeader, "files", chmd_header_files, 0);
|
100
|
+
|
101
|
+
ChmDFile = rb_define_class_under(ChmDecom, "File", rb_cObject);
|
102
|
+
rb_define_method(ChmDFile, "filename", chmd_file_filename, 0);
|
103
|
+
rb_define_method(ChmDFile, "next", chmd_file_next, 0);
|
104
|
+
}
|
@@ -1,10 +1,9 @@
|
|
1
|
+
#include "mspack_native.h"
|
2
|
+
#include "chm_decompressor.h"
|
3
|
+
|
1
4
|
#include <mspack.h>
|
2
|
-
#include <ruby.h>
|
3
5
|
|
4
6
|
VALUE Mspack = Qnil;
|
5
|
-
VALUE ChmDecom = Qnil;
|
6
|
-
VALUE ChmDHeader = Qnil;
|
7
|
-
VALUE ChmDFile = Qnil;
|
8
7
|
|
9
8
|
VALUE mspack_test() {
|
10
9
|
int result;
|
@@ -12,102 +11,9 @@ VALUE mspack_test() {
|
|
12
11
|
return result == MSPACK_ERR_OK ? Qtrue : Qfalse;
|
13
12
|
}
|
14
13
|
|
15
|
-
void chmd_deallocate(void *decom) {
|
16
|
-
mspack_destroy_chm_decompressor(decom);
|
17
|
-
}
|
18
|
-
|
19
|
-
static VALUE chmd_allocate(VALUE self) {
|
20
|
-
struct mschm_decompressor *decom = mspack_create_chm_decompressor(NULL);
|
21
|
-
return Data_Wrap_Struct(self, NULL, chmd_deallocate, decom);
|
22
|
-
}
|
23
|
-
|
24
|
-
static VALUE chmd_open(VALUE self, VALUE path) {
|
25
|
-
struct mschm_decompressor *decom;
|
26
|
-
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
27
|
-
struct mschmd_header *header = decom->open(decom, StringValueCStr(path));
|
28
|
-
|
29
|
-
if (!header) {
|
30
|
-
return Qnil;
|
31
|
-
}
|
32
|
-
|
33
|
-
VALUE headerObj = rb_obj_alloc(ChmDHeader);
|
34
|
-
rb_obj_call_init(headerObj, 0, NULL);
|
35
|
-
return Data_Wrap_Struct(ChmDHeader, NULL, NULL, header);
|
36
|
-
}
|
37
|
-
|
38
|
-
static VALUE chmd_close(VALUE self, VALUE header) {
|
39
|
-
struct mschm_decompressor *decom;
|
40
|
-
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
41
|
-
|
42
|
-
struct mschmd_header *headerPtr;
|
43
|
-
Data_Get_Struct(header, struct mschmd_header, headerPtr);
|
44
|
-
|
45
|
-
decom->close(decom, headerPtr);
|
46
|
-
return Qnil;
|
47
|
-
}
|
48
|
-
|
49
|
-
static VALUE chmd_extract(VALUE self, VALUE file, VALUE outputPath) {
|
50
|
-
struct mschm_decompressor *decom;
|
51
|
-
Data_Get_Struct(self, struct mschm_decompressor, decom);
|
52
|
-
|
53
|
-
struct mschmd_file *filePtr;
|
54
|
-
Data_Get_Struct(file, struct mschmd_file, filePtr);
|
55
|
-
|
56
|
-
const char *pathStr = StringValueCStr(outputPath);
|
57
|
-
return decom->extract(decom, filePtr, pathStr) == MSPACK_ERR_OK ?
|
58
|
-
Qtrue : Qfalse;
|
59
|
-
}
|
60
|
-
|
61
|
-
static VALUE chmd_header_filename(VALUE self) {
|
62
|
-
struct mschmd_header *header;
|
63
|
-
Data_Get_Struct(self, struct mschmd_header, header);
|
64
|
-
return rb_str_new2(header->filename);
|
65
|
-
}
|
66
|
-
|
67
|
-
static VALUE chmd_header_files(VALUE self) {
|
68
|
-
struct mschmd_header *header;
|
69
|
-
Data_Get_Struct(self, struct mschmd_header, header);
|
70
|
-
|
71
|
-
VALUE fileObj = rb_obj_alloc(ChmDFile);
|
72
|
-
rb_obj_call_init(fileObj, 0, NULL);
|
73
|
-
return Data_Wrap_Struct(ChmDFile, NULL, NULL, header->files);
|
74
|
-
}
|
75
|
-
|
76
|
-
static VALUE chmd_file_filename(VALUE self) {
|
77
|
-
struct mschmd_file *file;
|
78
|
-
Data_Get_Struct(self, struct mschmd_file, file);
|
79
|
-
return rb_str_new2(file->filename);
|
80
|
-
}
|
81
|
-
|
82
|
-
static VALUE chmd_file_next(VALUE self) {
|
83
|
-
struct mschmd_file *file;
|
84
|
-
Data_Get_Struct(self, struct mschmd_file, file);
|
85
|
-
struct mschmd_file *next = file->next;
|
86
|
-
|
87
|
-
if (next == NULL) {
|
88
|
-
return Qnil;
|
89
|
-
}
|
90
|
-
|
91
|
-
VALUE nextObj = rb_obj_alloc(ChmDFile);
|
92
|
-
rb_obj_call_init(nextObj, 0, NULL);
|
93
|
-
return Data_Wrap_Struct(ChmDFile, NULL, NULL, next);
|
94
|
-
}
|
95
|
-
|
96
14
|
void Init_mspack_native() {
|
97
15
|
Mspack = rb_define_module("Mspack");
|
98
16
|
rb_define_singleton_method(Mspack, "test", mspack_test, 0);
|
99
17
|
|
100
|
-
|
101
|
-
rb_define_alloc_func(ChmDecom, chmd_allocate);
|
102
|
-
rb_define_method(ChmDecom, "open", chmd_open, 1);
|
103
|
-
rb_define_method(ChmDecom, "close", chmd_close, 1);
|
104
|
-
rb_define_method(ChmDecom, "extract", chmd_extract, 2);
|
105
|
-
|
106
|
-
ChmDHeader = rb_define_class_under(ChmDecom, "Header", rb_cObject);
|
107
|
-
rb_define_method(ChmDHeader, "filename", chmd_header_filename, 0);
|
108
|
-
rb_define_method(ChmDHeader, "files", chmd_header_files, 0);
|
109
|
-
|
110
|
-
ChmDFile = rb_define_class_under(ChmDecom, "File", rb_cObject);
|
111
|
-
rb_define_method(ChmDFile, "filename", chmd_file_filename, 0);
|
112
|
-
rb_define_method(ChmDFile, "next", chmd_file_next, 0);
|
18
|
+
Init_chm_decompressor();
|
113
19
|
}
|
data/lib/mspack/version.rb
CHANGED
data/lib/mspack.rb
CHANGED
data/lib/mspack_native.bundle
CHANGED
Binary file
|
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.1.
|
4
|
+
version: 0.1.4
|
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-03-
|
11
|
+
date: 2017-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,8 +97,11 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- bin/console
|
99
99
|
- bin/setup
|
100
|
+
- ext/mspack_native/chm_decompressor.c
|
101
|
+
- ext/mspack_native/chm_decompressor.h
|
100
102
|
- ext/mspack_native/extconf.rb
|
101
103
|
- ext/mspack_native/mspack_native.c
|
104
|
+
- ext/mspack_native/mspack_native.h
|
102
105
|
- lib/mspack.rb
|
103
106
|
- lib/mspack/chm_decompressor.rb
|
104
107
|
- lib/mspack/version.rb
|