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 = nil) ⇒ Object
Expects a ChmDecompressor::File and a string.
-
#extract_to_path(*args) ⇒ Object
Form 1: extract_to_path(file, outputPath).
- #fast_find(header, filename) ⇒ Object
- #fast_open(path) ⇒ Object
- #last_error ⇒ Object
- #open(path) ⇒ Object
Instance Method Details
#close(header) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'ext/mspack_native/chm_decompressor.c', line 115 VALUE chmd_close(VALUE self, VALUE header) { if (!CLASS_OF(header) == ChmDHeader) { rb_raise(rb_eTypeError, "Parameter must be a CHM decompression header"); } struct decom_wrapper *wrapper; Data_Get_Struct(self, struct decom_wrapper, wrapper); struct mschmd_header *headerPtr; Data_Get_Struct(header, struct mschmd_header, headerPtr); wrapper->decom->close(wrapper->decom, headerPtr); return Qnil; } |
#extract(file, dir = nil) ⇒ 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 14 15 16 17 18 |
# File 'lib/mspack/chm_decompressor.rb', line 9 def extract(file, dir = nil) if block_given? extract_to_path(file) { |data| yield data } else path = Mspack.ensure_path(file.filename, dir) extract_to_path(file, path) end path end |
#extract_to_path(*args) ⇒ Object
Form 1: extract_to_path(file, outputPath)
Form 2: extract_to_path(file) { |data_chunk| do_something(data_chunk) }
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'ext/mspack_native/chm_decompressor.c', line 137 VALUE chmd_extract_to_path(int argc, VALUE* argv, VALUE self) { VALUE file; VALUE outputPath; rb_scan_args(argc, argv, "11", &file, &outputPath); const char *pathStr; if (!CLASS_OF(file) == ChmDFile) { rb_raise(rb_eTypeError, "First parameter must be a CHM decompression file"); } if (argc == 1) { rb_need_block(); VALUE block = rb_block_proc(); VALUE block_name = rb_funcall(block, rb_intern("object_id"), 0); VALUE block_name_str = rb_funcall(block_name, rb_intern("to_s"), 0); pathStr = StringValueCStr(block_name_str); } else { Check_Type(outputPath, T_STRING); pathStr = StringValueCStr(outputPath); } struct decom_wrapper *wrapper; Data_Get_Struct(self, struct decom_wrapper, wrapper); struct chmd_file_wrapper *headerWrapper; Data_Get_Struct(file, struct chmd_file_wrapper, headerWrapper); int result = wrapper->decom->extract(wrapper->decom, headerWrapper->file, pathStr); return result == MSPACK_ERR_OK ? Qtrue : Qfalse; } |
#fast_find(header, filename) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'ext/mspack_native/chm_decompressor.c', line 183 VALUE chmd_fast_find(VALUE self, VALUE header, VALUE filename) { struct decom_wrapper *wrapper; Data_Get_Struct(self, struct decom_wrapper, wrapper); 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 = wrapper->decom->fast_find( wrapper->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); struct chmd_file_wrapper *fileWrapper = malloc(sizeof(struct chmd_file_wrapper)); fileWrapper->is_fast_find = 1; fileWrapper->file = file; return Data_Wrap_Struct(ChmDFile, NULL, chmd_file_free, fileWrapper); } |
#fast_open(path) ⇒ Object
179 180 181 |
# File 'ext/mspack_native/chm_decompressor.c', line 179 VALUE chmd_fast_open(VALUE self, VALUE path) { return _open(self, path, 1); } |
#last_error ⇒ Object
171 172 173 174 175 176 177 |
# File 'ext/mspack_native/chm_decompressor.c', line 171 VALUE chmd_last_error(VALUE self) { struct decom_wrapper *wrapper; Data_Get_Struct(self, struct decom_wrapper, wrapper); int error = wrapper->decom->last_error(wrapper->decom); return _error_code_sym(error); } |
#open(path) ⇒ Object
111 112 113 |
# File 'ext/mspack_native/chm_decompressor.c', line 111 VALUE chmd_open(VALUE self, VALUE path) { return _open(self, path, 0); } |