Class: Mspack::ChmDecompressor
- Inherits:
-
Object
- Object
- Mspack::ChmDecompressor
- Defined in:
- lib/mspack/chm_decompressor.rb,
ext/mspack_native/chm_decompressor.c
Defined Under Namespace
Instance Method Summary collapse
- #close(header) ⇒ Object
-
#extract(file, dir) ⇒ Object
Expects a ChmDecompressor::File and a string.
- #extract_to_path(file, outputPath) ⇒ Object
- #fast_find(header, filename) ⇒ Object
- #fast_open(path) ⇒ Object
- #last_error ⇒ Object
- #open(path) ⇒ Object
Instance Method Details
#close(header) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/mspack_native/chm_decompressor.c', line 102
VALUE chmd_close(VALUE self, VALUE header) {
if (!CLASS_OF(header) == ChmDHeader) {
rb_raise(rb_eTypeError, "Parameter must be a CHM decompression header");
}
struct mschm_decompressor *decom;
Data_Get_Struct(self, struct mschm_decompressor, decom);
struct mschmd_header *headerPtr;
Data_Get_Struct(header, struct mschmd_header, headerPtr);
decom->close(decom, headerPtr);
return Qnil;
}
|
#extract(file, dir) ⇒ Object
Expects a ChmDecompressor::File and a string. Calls Mspack.ensure_path and extracts file. Returns the absolute file path.
9 10 11 12 13 |
# File 'lib/mspack/chm_decompressor.rb', line 9 def extract(file, dir) path = Mspack.ensure_path(file.filename, dir) extract_to_path(file, path) path end |
#extract_to_path(file, outputPath) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/mspack_native/chm_decompressor.c', line 117
VALUE chmd_extract_to_path(VALUE self, VALUE file, VALUE outputPath) {
if (!CLASS_OF(file) == ChmDFile) {
rb_raise(rb_eTypeError, "First parameter must be a CHM decompression file");
}
Check_Type(outputPath, T_STRING);
struct mschm_decompressor *decom;
Data_Get_Struct(self, struct mschm_decompressor, decom);
struct mschmd_file *filePtr;
Data_Get_Struct(file, struct mschmd_file, filePtr);
const char *pathStr = StringValueCStr(outputPath);
int result = decom->extract(decom, filePtr, pathStr);
return result == MSPACK_ERR_OK ? Qtrue : Qfalse;
}
|
#fast_find(header, filename) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/mspack_native/chm_decompressor.c', line 147
VALUE chmd_fast_find(VALUE self, VALUE header, VALUE filename) {
struct mschm_decompressor *decom;
Data_Get_Struct(self, struct mschm_decompressor, decom);
struct mschmd_header *headerPtr;
Data_Get_Struct(header, struct mschmd_header, headerPtr);
const char *filenameStr = StringValueCStr(filename);
int structSize = sizeof(struct mschmd_file);
struct mschmd_file *file = malloc(structSize);
int result =
decom->fast_find(decom, headerPtr, filenameStr, file, structSize);
if (result != MSPACK_ERR_OK || file->length == 0) {
free(file);
return Qnil;
}
file->filename = malloc(sizeof(char) * strlen(filenameStr) + 1);
strcpy(file->filename, filenameStr);
VALUE fileObj = Data_Wrap_Struct(ChmDFile, NULL, NULL, file);
rb_iv_set(fileObj, "is_fast_find", Qtrue);
return fileObj;
}
|
#fast_open(path) ⇒ Object
143 144 145 |
# File 'ext/mspack_native/chm_decompressor.c', line 143
VALUE chmd_fast_open(VALUE self, VALUE path) {
return _open(self, path, 1);
}
|
#last_error ⇒ Object
135 136 137 138 139 140 141 |
# File 'ext/mspack_native/chm_decompressor.c', line 135
VALUE chmd_last_error(VALUE self) {
struct mschm_decompressor *decom;
Data_Get_Struct(self, struct mschm_decompressor, decom);
int error = decom->last_error(decom);
return _error_code_sym(error);
}
|
#open(path) ⇒ Object
98 99 100 |
# File 'ext/mspack_native/chm_decompressor.c', line 98
VALUE chmd_open(VALUE self, VALUE path) {
return _open(self, path, 0);
}
|