Mercurial > octave
annotate libinterp/dldfcn/gzip.cc @ 22922:426325aa8ee9 stable
Fix gzip for certain types of gzip files (bug #49760).
* gzip.cc (deflate): Follow example code from zlib and quit loop based on feof
rather than on return status of fread.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 18 Dec 2016 07:09:49 -0800 |
parents | 93ea313301f9 |
children | b150be19734d e9a0469dedd9 |
rev | line source |
---|---|
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
1 // Copyright (C) 2016 Carnë Draug |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
2 // |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
3 // This program is free software: you can redistribute it and/or modify |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
4 // it under the terms of the GNU General Public License as published by |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
5 // the Free Software Foundation, either version 3 of the License, or |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
6 // (at your option) any later version. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
7 // |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
8 // This program is distributed in the hope that it will be useful, |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
11 // GNU General Public License for more details. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
12 // |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
13 // You should have received a copy of the GNU General Public License |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
14 // along with this program. If not, see <http://www.gnu.org/licenses/>. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
15 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
16 //! Octave interface to the compression and uncompression libraries. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
17 /*! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
18 This was originally implemented as an m file which directly called |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
19 bzip2 and gzip applications. This may look simpler but causes some |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
20 issues (see bug #43431) because we have no control over the output |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
21 file: |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
22 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
23 - created file is always in the same directory as the original file; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
24 - automatically skip files that already have gz/bz2/etc extension; |
22299
9fc91bb2aec3
doc: grammarcheck documentation for 4.2 release.
Rik <rik@octave.org>
parents:
22271
diff
changeset
|
25 - some older versions lack the --keep option. |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
26 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
27 In addition, because system() does not have a method that allows |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
28 passing a list of arguments, there is the issue of having to escape |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
29 filenames. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
30 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
31 A solution is to pipe file contents into the applications instead of |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
32 filenames. However, that solution causes: |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
33 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
34 # missing file header with original file information; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
35 # implementing ourselves the recursive transversion of directories; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
36 # do the above in a m file which will be slow; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
37 # popen2 is frail on windows. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
38 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
39 */ |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
40 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
41 #if defined (HAVE_CONFIG_H) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
42 # include "config.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
43 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
44 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
45 #include <cstdio> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
46 #include <cstring> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
47 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
48 #include <string> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
49 #include <list> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
50 #include <functional> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
51 #include <stdexcept> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
52 #include <iostream> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
53 #include <fstream> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
54 |
22188 | 55 #if defined (HAVE_BZLIB_H) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
56 # include <bzlib.h> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
57 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
58 |
22188 | 59 #if defined (HAVE_ZLIB_H) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
60 # include <zlib.h> |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
61 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
62 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
63 #include "Array.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
64 #include "str-vec.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
65 #include "glob-match.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
66 #include "file-ops.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
67 #include "dir-ops.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
68 #include "file-stat.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
69 #include "oct-env.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
70 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
71 #include "defun-dld.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
72 #include "defun-int.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
73 #include "errwarn.h" |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
74 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
75 namespace octave |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
76 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
77 //! RIIA wrapper for std::FILE* |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
78 /*! If error handling is available for failing to close the file, use |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
79 the close method which throws. |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
80 |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
81 If the file has been closed, fp is set to nullptr. Remember that |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
82 behavior is undefined if the value of the pointer stream is used |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
83 after fclose. |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
84 */ |
22188 | 85 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
86 class CFile |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
87 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
88 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
89 std::FILE* fp; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
90 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
91 CFile (const std::string& path, const std::string& mode) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
92 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
93 fp = std::fopen (path.c_str (), mode.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
94 if (! fp) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
95 throw std::runtime_error ("unable to open file"); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
96 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
97 |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
98 void |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
99 close (void) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
100 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
101 if (std::fclose (fp)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
102 throw std::runtime_error ("unable to close file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
103 fp = nullptr; |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
104 } |
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
105 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
106 ~CFile () |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
107 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
108 if (fp) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
109 std::fclose (fp); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
110 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
111 }; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
112 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
113 #if defined (HAVE_BZ2) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
114 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
115 class bz2 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
116 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
117 private: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
118 class zipper |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
119 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
120 private: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
121 int status = BZ_OK; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
122 CFile source; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
123 CFile dest; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
124 BZFILE* bz; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
125 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
126 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
127 zipper (const std::string& source_path, const std::string& dest_path) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
128 : source (source_path, "rb"), dest (dest_path, "wb") |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
129 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
130 bz = BZ2_bzWriteOpen (&status, dest.fp, 9, 0, 30); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
131 if (status != BZ_OK) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
132 throw std::runtime_error ("failed to open bzip2 stream"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
133 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
134 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
135 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
136 deflate (void) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
137 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
138 const std::size_t buf_len = 8192; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
139 char buf[buf_len]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
140 std::size_t n_read; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
141 while ((n_read = std::fread (buf, sizeof (buf[0]), buf_len, source.fp)) != 0) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
142 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
143 if (std::ferror (source.fp)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
144 throw std::runtime_error ("failed to read from source file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
145 BZ2_bzWrite (&status, bz, buf, n_read); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
146 if (status == BZ_IO_ERROR) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
147 throw std::runtime_error ("failed to write or compress"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
148 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
149 if (std::ferror (source.fp)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
150 throw std::runtime_error ("failed to read from source file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
151 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
152 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
153 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
154 close (void) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
155 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
156 int abandon = (status == BZ_IO_ERROR) ? 1 : 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
157 BZ2_bzWriteClose (&status, bz, abandon, 0, 0); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
158 if (status != BZ_OK) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
159 throw std::runtime_error ("failed to close bzip2 stream"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
160 bz = nullptr; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
161 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
162 // We have no error handling for failing to close source, let |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
163 // the destructor close it. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
164 dest.close (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
165 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
166 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
167 ~zipper () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
168 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
169 if (bz != nullptr) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
170 BZ2_bzWriteClose (&status, bz, 1, 0, 0); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
171 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
172 }; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
173 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
174 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
175 static const constexpr char* extension = ".bz2"; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
176 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
177 static void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
178 zip (const std::string& source_path, const std::string& dest_path) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
179 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
180 bz2::zipper z (source_path, dest_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
181 z.deflate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
182 z.close (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
183 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
184 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
185 }; |
22188 | 186 |
187 #endif | |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
188 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
189 // Note about zlib and gzip |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
190 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
191 // gzip is a format for compressed single files. zlib is a format |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
192 // designed for in-memory and communication channel applications. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
193 // gzip uses the same format internally for the compressed data but |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
194 // has different headers and trailers. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
195 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
196 // zlib is also a library but gzip is not. Very old versions of zlib do |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
197 // not include functions to create useful gzip headers and trailers: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
198 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
199 // Note that you cannot specify special gzip header contents (e.g. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
200 // a file name or modification date), nor will inflate tell you what |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
201 // was in the gzip header. If you need to customize the header or |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
202 // see what's in it, you can use the raw deflate and inflate |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
203 // operations and the crc32() function and roll your own gzip |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
204 // encoding and decoding. Read the gzip RFC 1952 for details of the |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
205 // header and trailer format. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
206 // zlib FAQ |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
207 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
208 // Recent versions (on which we are already dependent) have deflateInit2() |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
209 // to do it. We still need to get the right metadata for the header |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
210 // ourselves though. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
211 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
212 // The header is defined in RFC #1952 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
213 // GZIP file format specification version 4.3 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
214 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
215 |
22188 | 216 #if defined (HAVE_Z) |
217 | |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
218 class gz |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
219 { |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
220 private: |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
221 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
222 // Util class to get a non-const char* |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
223 class uchar_array |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
224 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
225 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
226 // Bytef is a typedef for unsigned char |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
227 unsigned char* p; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
228 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
229 uchar_array (const std::string& str) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
230 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
231 p = new Bytef[str.length () +1]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
232 std::strcpy (reinterpret_cast<char*> (p), str.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
233 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
234 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
235 ~uchar_array (void) { delete[] p; } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
236 }; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
237 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
238 class gzip_header : public gz_header |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
239 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
240 private: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
241 // This must be kept for gz_header.name |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
242 uchar_array basename; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
243 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
244 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
245 gzip_header (const std::string& source_path) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
246 : basename (octave::sys::env::base_pathname (source_path)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
247 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
248 const octave::sys::file_stat source_stat (source_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
249 if (! source_stat) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
250 throw std::runtime_error ("unable to stat source file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
251 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
252 // time_t may be a signed int in which case it will be a |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
253 // positive number so it is safe to uLong. Or is it? Can |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
254 // unix_time really never be negative? |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
255 time = uLong (source_stat.mtime ().unix_time ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
256 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
257 // If FNAME is set, an original file name is present, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
258 // terminated by a zero byte. The name must consist of ISO |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
259 // 8859-1 (LATIN-1) characters; on operating systems using |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
260 // EBCDIC or any other character set for file names, the name |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
261 // must be translated to the ISO LATIN-1 character set. This |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
262 // is the original name of the file being compressed, with any |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
263 // directory components removed, and, if the file being |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
264 // compressed is on a file system with case insensitive names, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
265 // forced to lower case. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
266 name = basename.p; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
267 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
268 // If we don't set it to Z_NULL, then it will set FCOMMENT (4th bit) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
269 // on the FLG byte, and then write {0, 3} comment. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
270 comment = Z_NULL; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
271 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
272 // Seems to already be the default but we are not taking chances. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
273 extra = Z_NULL; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
274 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
275 // We do not want a CRC for the header. That would be only 2 more |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
276 // bytes, and maybe it would be a good thing but we want to generate |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
277 // gz files similar to the default gzip application. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
278 hcrc = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
279 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
280 // OS (Operating System): |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
281 // 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
282 // 1 - Amiga |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
283 // 2 - VMS (or OpenVMS) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
284 // 3 - Unix |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
285 // 4 - VM/CMS |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
286 // 5 - Atari TOS |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
287 // 6 - HPFS filesystem (OS/2, NT) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
288 // 7 - Macintosh |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
289 // 8 - Z-System |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
290 // 9 - CP/M |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
291 // 10 - TOPS-20 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
292 // 11 - NTFS filesystem (NT) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
293 // 12 - QDOS |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
294 // 13 - Acorn RISCOS |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
295 // 255 - unknown |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
296 // |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
297 // The list is problematic because it mixes OS and filesystem. It |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
298 // also does not specify whether filesystem relates to source or |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
299 // destination file. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
300 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
301 #if defined (__WIN32__) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
302 // Or should it be 11? |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
303 os = 0; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
304 #elif defined (__APPLE__) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
305 os = 7; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
306 #else |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
307 // Unix by default? |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
308 os = 3; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
309 #endif |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
310 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
311 }; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
312 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
313 class zipper |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
314 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
315 private: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
316 CFile source; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
317 CFile dest; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
318 gzip_header header; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
319 z_stream* strm; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
320 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
321 public: |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
322 zipper (const std::string& source_path, const std::string& dest_path) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
323 : source (source_path, "rb"), dest (dest_path, "wb"), |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
324 header (source_path), strm (new z_stream) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
325 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
326 strm->zalloc = Z_NULL; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
327 strm->zfree = Z_NULL; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
328 strm->opaque = Z_NULL; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
329 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
330 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
331 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
332 deflate () |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
333 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
334 // int deflateInit2 (z_streamp strm, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
335 // int level, // compression level (default is 8) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
336 // int method, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
337 // int windowBits, // 15 (default) + 16 (gzip format) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
338 // int memLevel, // memory usage (default is 8) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
339 // int strategy); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
340 int status = deflateInit2 (strm, 8, Z_DEFLATED, 31, 8, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
341 Z_DEFAULT_STRATEGY); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
342 if (status != Z_OK) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
343 throw std::runtime_error ("failed to open zlib stream"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
344 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
345 deflateSetHeader (strm, &header); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
346 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
347 const std::size_t buf_len = 8192; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
348 unsigned char buf_in[buf_len]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
349 unsigned char buf_out[buf_len]; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
350 |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
351 int flush; |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
352 |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
353 do |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
354 { |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
355 strm->avail_in = std::fread (buf_in, sizeof (buf_in[0]), |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
356 buf_len, source.fp); |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
357 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
358 if (std::ferror (source.fp)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
359 throw std::runtime_error ("failed to read source file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
360 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
361 strm->next_in = buf_in; |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
362 flush = std::feof (source.fp) ? Z_FINISH : Z_NO_FLUSH; |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
363 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
364 // If deflate returns Z_OK and with zero avail_out, it must be |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
365 // called again after making room in the output buffer because |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
366 // there might be more output pending. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
367 do |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
368 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
369 strm->avail_out = buf_len; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
370 strm->next_out = buf_out; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
371 status = ::deflate (strm, flush); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
372 if (status == Z_STREAM_ERROR) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
373 throw std::runtime_error ("failed to deflate"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
374 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
375 std::fwrite (buf_out, sizeof (buf_out[0]), |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
376 buf_len - strm->avail_out, dest.fp); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
377 if (std::ferror (dest.fp)) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
378 throw std::runtime_error ("failed to write file"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
379 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
380 while (strm->avail_out == 0); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
381 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
382 if (strm->avail_in != 0) |
22922
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
383 throw std::runtime_error ("failed to write file"); |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
384 |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
385 } while (flush != Z_FINISH); |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
386 |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
387 if (status != Z_STREAM_END) |
426325aa8ee9
Fix gzip for certain types of gzip files (bug #49760).
Rik <rik@octave.org>
parents:
22489
diff
changeset
|
388 throw std::runtime_error ("failed to write file"); |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
389 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
390 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
391 void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
392 close (void) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
393 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
394 if (deflateEnd (strm) != Z_OK) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
395 throw std::runtime_error ("failed to close zlib stream"); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
396 strm = nullptr; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
397 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
398 // We have no error handling for failing to close source, let |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
399 // the destructor close it. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
400 dest.close (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
401 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
402 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
403 ~zipper (void) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
404 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
405 if (strm) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
406 deflateEnd (strm); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
407 delete strm; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
408 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
409 }; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
410 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
411 public: |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
412 static const constexpr char* extension = ".gz"; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
413 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
414 static void |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
415 zip (const std::string& source_path, const std::string& dest_path) |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
416 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
417 gz::zipper z (source_path, dest_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
418 z.deflate (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
419 z.close (); |
22187
2aae8894885b
xzip.cc: replace throwing exceptions in destructors (bug #48640)
Carnë Draug <carandraug@octave.org>
parents:
22173
diff
changeset
|
420 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
421 }; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
422 |
22188 | 423 #endif |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
424 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
425 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
426 template<typename X> |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
427 string_vector |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
428 xzip (const Array<std::string>& source_patterns, |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
429 const std::function<std::string(const std::string&)>& mk_dest_path) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
430 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
431 std::list<std::string> dest_paths; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
432 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
433 std::function<void(const std::string&)> walk; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
434 walk = [&walk, &mk_dest_path, &dest_paths] (const std::string& path) -> void |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
435 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
436 const octave::sys::file_stat fs (path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
437 // is_dir and is_reg will return false if failed to stat. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
438 if (fs.is_dir ()) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
439 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
440 octave::sys::dir_entry dir (path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
441 if (dir) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
442 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
443 // Collect the whole list of filenames first, before recursion |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
444 // to avoid issues with infinite loop if the action generates |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
445 // files in the same directory (highly likely). |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
446 string_vector dirlist = dir.read (); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
447 for (octave_idx_type i = 0; i < dirlist.numel (); i++) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
448 if (dirlist(i) != "." && dirlist(i) != "..") |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
449 walk (octave::sys::file_ops::concat (path, dirlist(i))); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
450 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
451 // Note that we skip any problem with directories. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
452 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
453 else if (fs.is_reg ()) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
454 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
455 const std::string dest_path = mk_dest_path (path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
456 try |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
457 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
458 X::zip (path, dest_path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
459 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
460 catch (...) |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
461 { |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
462 // Error "handling" is not including filename on the output list. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
463 // Also remove created file which maybe was not even created |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
464 // in the first place. Note that it is possible for the file |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
465 // to exist in the first place and for X::zip to not have |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
466 // clobber it yet but we remove it anyway by design. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
467 octave::sys::unlink (dest_path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
468 return; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
469 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
470 dest_paths.push_front (dest_path); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
471 } |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
472 // Skip all other file types and errors. |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
473 return; |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
474 }; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
475 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
476 for (octave_idx_type i = 0; i < source_patterns.numel (); i++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
477 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
478 const glob_match pattern (octave::sys::file_ops::tilde_expand (source_patterns(i))); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
479 const string_vector filepaths = pattern.glob (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
480 for (octave_idx_type j = 0; j < filepaths.numel (); j++) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
481 walk (filepaths(j)); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
482 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
483 return string_vector (dest_paths); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
484 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
485 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
486 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
487 template<typename X> |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
488 string_vector |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
489 xzip (const Array<std::string>& source_patterns) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
490 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
491 const std::string ext = X::extension; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
492 const std::function<std::string(const std::string&)> mk_dest_path |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
493 = [&ext] (const std::string& source_path) -> std::string |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
494 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
495 return source_path + ext; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
496 }; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
497 return xzip<X> (source_patterns, mk_dest_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
498 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
499 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
500 template<typename X> |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
501 string_vector |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
502 xzip (const Array<std::string>& source_patterns, const std::string& out_dir) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
503 { |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
504 const std::string ext = X::extension; |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
505 const std::function<std::string(const std::string&)> mk_dest_path |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
506 = [&out_dir, &ext] (const std::string& source_path) -> std::string |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
507 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
508 const std::string basename = octave::sys::env::base_pathname (source_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
509 return octave::sys::file_ops::concat (out_dir, basename + ext); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
510 }; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
511 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
512 // We don't care if mkdir fails. Maybe it failed because it already |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
513 // exists, or maybe it can't bre created. If the first, then there's |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
514 // nothing to do, if the later, then it will be handled later. Any |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
515 // is to be handled by not listing files in the output. |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
516 octave::sys::mkdir (out_dir, 0777); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
517 return xzip<X> (source_patterns, mk_dest_path); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
518 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
519 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
520 template<typename X> |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
521 static octave_value_list |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
522 xzip (const std::string& func_name, const octave_value_list& args) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
523 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
524 const octave_idx_type nargin = args.length (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
525 if (nargin < 1 || nargin > 2) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
526 print_usage (); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
527 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
528 const Array<std::string> source_patterns |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
529 = args(0).xcellstr_value ("%s: FILES must be a character array or cellstr", |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
530 func_name.c_str ()); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
531 if (nargin == 1) |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
532 return octave_value (Cell (xzip<X> (source_patterns))); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
533 else // nargin == 2 |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
534 { |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
535 const std::string out_dir = args(1).string_value (); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
536 return octave_value (Cell (xzip<X> (source_patterns, out_dir))); |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
537 } |
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
538 } |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
539 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
540 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
541 DEFUN_DLD (gzip, args, , |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
542 doc: /* -*- texinfo -*- |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
543 @deftypefn {} {@var{filelist} =} gzip (@var{files}) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
544 @deftypefnx {} {@var{filelist} =} gzip (@var{files}, @var{dir}) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
545 Compress the list of files and directories specified in @var{files}. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
546 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
547 @var{files} is a character array or cell array of strings. Shell wildcards |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
548 in the filename such as @samp{*} or @samp{?} are accepted and expanded. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
549 Each file is compressed separately and a new file with a @file{".gz"} |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
550 extension is created. The original files are not modified, but existing |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
551 compressed files will be silently overwritten. If a directory is |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
552 specified then @code{gzip} recursively compresses all files in the |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
553 directory. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
554 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
555 If @var{dir} is defined the compressed files are placed in this directory, |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
556 rather than the original directory where the uncompressed file resides. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
557 Note that this does not replicate a directory tree in @var{dir} which may |
22330
53e246fd8124
doc: Spellcheck documentation ahead of 4.2 release.
Rik <rik@octave.org>
parents:
22326
diff
changeset
|
558 lead to files overwriting each other if there are multiple files with the |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
559 same name. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
560 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
561 If @var{dir} does not exist it is created. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
562 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
563 The optional output @var{filelist} is a list of the compressed files. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
564 @seealso{gunzip, unpack, bzip2, zip, tar} |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
565 @end deftypefn */) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
566 { |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
567 #if defined (HAVE_Z) |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
568 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
569 return octave::xzip<octave::gz> ("gzip", args); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
570 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
571 #else |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
572 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
573 octave_unused_parameter (args); |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
574 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
575 err_disabled_feature ("gzip", "gzip"); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
576 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
577 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
578 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
579 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
580 /* |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
581 %!error gzip () |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
582 %!error gzip ("1", "2", "3") |
22271
16efd0403698
Add %!error test pattern matches for disabled optional features
Mike Miller <mtmiller@octave.org>
parents:
22269
diff
changeset
|
583 %!error <FILES must be a character array or cellstr|was unavailable or disabled> gzip (1) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
584 */ |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
585 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
586 DEFUN_DLD (bzip2, args, , |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
587 doc: /* -*- texinfo -*- |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
588 @deftypefn {} {@var{filelist} =} bzip2 (@var{files}) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
589 @deftypefnx {} {@var{filelist} =} bzip2 (@var{files}, @var{dir}) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
590 Compress the list of files specified in @var{files}. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
591 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
592 @var{files} is a character array or cell array of strings. Shell wildcards |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
593 in the filename such as @samp{*} or @samp{?} are accepted and expanded. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
594 Each file is compressed separately and a new file with a @file{".bz2"} |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
595 extension is created. The original files are not modified, but existing |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
596 compressed files will be silently overwritten. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
597 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
598 If @var{dir} is defined the compressed files are placed in this directory, |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
599 rather than the original directory where the uncompressed file resides. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
600 Note that this does not replicate a directory tree in @var{dir} which may |
22330
53e246fd8124
doc: Spellcheck documentation ahead of 4.2 release.
Rik <rik@octave.org>
parents:
22326
diff
changeset
|
601 lead to files overwriting each other if there are multiple files with the |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
602 same name. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
603 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
604 If @var{dir} does not exist it is created. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
605 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
606 The optional output @var{filelist} is a list of the compressed files. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
607 @seealso{bunzip2, unpack, gzip, zip, tar} |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
608 @end deftypefn */) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
609 { |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
610 #if defined (HAVE_BZ2) |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
611 |
22326
71dd9d5a5ecd
move more new classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22299
diff
changeset
|
612 return octave::xzip<octave::bz2> ("bzip2", args); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
613 |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
614 #else |
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
615 |
22269
a76b931d2c4b
* xzip.cc (Fbzip2): Fix typo of "octave_unused_parameter".
Mike Miller <mtmiller@octave.org>
parents:
22265
diff
changeset
|
616 octave_unused_parameter (args); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
617 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
618 err_disabled_feature ("bzip2", "bzip2"); |
22265
15b9d7cb3098
eliminate unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
22194
diff
changeset
|
619 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
620 #endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
621 } |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
622 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
623 // Tests for both gzip/bzip2 and gunzip/bunzip2 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
624 /* |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
625 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
626 ## Takes a single argument, a function handle for the test. This other |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
627 ## function must accept two arguments, a directory for the tests, and |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
628 ## a cell array with zip function, unzip function, and file extension. |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
629 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
630 %!function run_test_function (test_function) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
631 %! enabled_zippers = struct ("zip", {}, "unzip", {}, "ext", {}); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
632 %! if (__octave_config_info__ ().build_features.BZ2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
633 %! enabled_zippers(end+1).zip = @bzip2; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
634 %! enabled_zippers(end).unzip = @bunzip2; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
635 %! enabled_zippers(end).ext = ".bz2"; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
636 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
637 %! if (__octave_config_info__ ().build_features.Z) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
638 %! enabled_zippers(end+1).zip = @gzip; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
639 %! enabled_zippers(end).unzip = @gunzip; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
640 %! enabled_zippers(end).ext = ".gz"; |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
641 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
642 %! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
643 %! for z = enabled_zippers |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
644 %! test_dir = tempname (); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
645 %! if (! mkdir (test_dir)) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
646 %! error ("unable to create directory for tests"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
647 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
648 %! unwind_protect |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
649 %! test_function (test_dir, z) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
650 %! unwind_protect_cleanup |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
651 %! confirm_recursive_rmdir (false, "local"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
652 %! rmdir (test_dir, "s"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
653 %! end_unwind_protect |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
654 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
655 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
656 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
657 %!function create_file (fpath, data) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
658 %! fid = fopen (fpath, "wb"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
659 %! if (fid < 0) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
660 %! error ("unable to open file for writing"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
661 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
662 %! if (fwrite (fid, data, class (data)) != numel (data)) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
663 %! error ("unable to write to file"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
664 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
665 %! if (fflush (fid) || fclose (fid)) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
666 %! error ("unable to flush or close file"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
667 %! endif |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
668 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
669 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
670 %!function unlink_or_error (filepath) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
671 %! [err, msg] = unlink (filepath); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
672 %! if (err) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
673 %! error ("unable to remove file required for the test"); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
674 %! endif |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
675 %!endfunction |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
676 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
677 ## Test with large files because of varied buffer size |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
678 %!function test_large_file (test_dir, z) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
679 %! test_file = tempname (test_dir); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
680 %! create_file (test_file, rand (500000, 1)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
681 %! md5 = hash ("md5", fileread (test_file)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
682 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
683 %! z_file = [test_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
684 %! z_filelist = z.zip (test_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
685 %! assert (z_filelist, {z_file}) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
686 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
687 %! unlink_or_error (test_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
688 %! uz_filelist = z.unzip (z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
689 %! assert (uz_filelist, {test_file}) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
690 %! |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
691 %! assert (hash ("md5", fileread (test_file)), md5) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
692 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
693 %!test run_test_function (@test_large_file) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
694 |
22352
d71ae2cd510b
build: Change known failures to xtest so that 'make check' produces a clean run.
Rik <rik@octave.org>
parents:
22339
diff
changeset
|
695 ## Test that xzipped files are rexzipped (hits bug #48597, #48598) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
696 %!function test_z_z (test_dir, z) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
697 %! ori_file = tempname (test_dir); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
698 %! create_file (ori_file, rand (100, 1)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
699 %! md5_ori = hash ("md5", fileread (ori_file)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
700 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
701 %! z_file = [ori_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
702 %! z_filelist = z.zip (ori_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
703 %! assert (z_filelist, {z_file}) # check output |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
704 %! assert (exist (z_file), 2) # confirm file exists |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
705 %! assert (exist (ori_file), 2) # and did not remove original file |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
706 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
707 %! unlink_or_error (ori_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
708 %! uz_filelist = z.unzip (z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
709 %! assert (uz_filelist, {ori_file}) # bug #48598 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
710 %! assert (hash ("md5", fileread (ori_file)), md5_ori) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
711 %! assert (exist (z_file), 2) # bug #48597 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
712 %! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
713 %! ## xzip should dutifully re-xzip files even if they already are zipped |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
714 %! z_z_file = [z_file z.ext]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
715 %! z_z_filelist = z.zip (z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
716 %! assert (z_z_filelist, {z_z_file}) # check output |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
717 %! assert (exist (z_z_file), 2) # confirm file exists |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
718 %! assert (exist (z_file), 2) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
719 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
720 %! md5_z = hash ("md5", fileread (z_file)); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
721 %! unlink_or_error (z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
722 %! uz_z_filelist = z.unzip (z_z_file); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
723 %! assert (uz_z_filelist, {z_file}) # bug #48598 |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
724 %! assert (exist (z_z_file), 2) # bug #48597 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
725 %! assert (hash ("md5", fileread (z_file)), md5_z) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
726 %!endfunction |
22489
93ea313301f9
test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
727 %!xtest run_test_function (@test_z_z) <48597> |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
728 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
729 %!function test_xzip_dir (test_dir, z) # bug #43431 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
730 %! fpaths = fullfile (test_dir, {"test1", "test2", "test3"}); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
731 %! md5s = cell (1, 3); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
732 %! for idx = 1:numel(fpaths) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
733 %! create_file (fpaths{idx}, rand (100, 1)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
734 %! md5s(idx) = hash ("md5", fileread (fpaths{idx})); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
735 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
736 %! |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
737 %! test_dir = [test_dir filesep()]; |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
738 %! |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
739 %! z_files = strcat (fpaths, z.ext); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
740 %! z_filelist = z.zip (test_dir); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
741 %! assert (sort (z_filelist), z_files(:)) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
742 %! for idx = 1:numel(fpaths) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
743 %! assert (exist (z_files{idx}), 2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
744 %! unlink_or_error (fpaths{idx}); |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
745 %! endfor |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
746 %! |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
747 %! ## only gunzip handles directory (bunzip2 should too though) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
748 %! if (z.unzip == @gunzip) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
749 %! uz_filelist = z.unzip (test_dir); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
750 %! else |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
751 %! uz_filelist = cell (1, numel (z_filelist)); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
752 %! for idx = 1:numel(z_filelist) |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
753 %! uz_filelist(idx) = z.unzip (z_filelist{idx}); |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
754 %! endfor |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
755 %! endif |
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
756 %! assert (sort (uz_filelist), fpaths(:)) # bug #48598 |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
757 %! for idx = 1:numel(fpaths) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
758 %! assert (hash ("md5", fileread (fpaths{idx})), md5s{idx}) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
759 %! endfor |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
760 %!endfunction |
22352
d71ae2cd510b
build: Change known failures to xtest so that 'make check' produces a clean run.
Rik <rik@octave.org>
parents:
22339
diff
changeset
|
761 %!xtest run_test_function (@test_xzip_dir) |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
762 |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
763 %!function test_save_to_dir (test_dir, z) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
764 %! filename = "test-file"; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
765 %! filepath = fullfile (test_dir, filename); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
766 %! create_file (filepath, rand (100, 1)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
767 %! md5 = hash ("md5", fileread (filepath)); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
768 %! |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
769 %! ## test with existing and non-existing directory |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
770 %! out_dirs = {tempname (test_dir), tempname (test_dir)}; |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
771 %! if (! mkdir (out_dirs{1})) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
772 %! error ("unable to create directory for test"); |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
773 %! endif |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
774 %! unwind_protect |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
775 %! for idx = 1:numel(out_dirs) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
776 %! out_dir = out_dirs{idx}; |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
777 %! uz_file = fullfile (out_dir, filename); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
778 %! z_file = [uz_file z.ext]; |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
779 %! |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
780 %! z_filelist = z.zip (filepath, out_dir); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
781 %! assert (z_filelist, {z_file}) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
782 %! assert (exist (z_file, "file"), 2) |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
783 %! |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
784 %! uz_filelist = z.unzip (z_file); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
785 %! assert (uz_filelist, {uz_file}) # bug #48598 |
22194
b1ebad209360
xzip.cc: modify tests for readability.
Carnë Draug <carandraug@octave.org>
parents:
22188
diff
changeset
|
786 %! |
22365
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
787 %! assert (hash ("md5", fileread (uz_file)), md5) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
788 %! endfor |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
789 %! unwind_protect_cleanup |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
790 %! confirm_recursive_rmdir (false, "local"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
791 %! for idx = 1:numel(out_dirs) |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
792 %! rmdir (out_dirs{idx}, "s"); |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
793 %! endfor |
119f408f2dd1
Remove temporary directories and files used by BIST.
Carnë Draug <carandraug@octave.org>
parents:
22352
diff
changeset
|
794 %! end_unwind_protect |
22160
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
795 %!endfunction |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
796 %!test run_test_function (@test_save_to_dir) |
766f934db568
Rewrite gzip and bzip2 in C++ instead of using its applications (bug #43431)
Carnë Draug <carandraug@octave.org>
parents:
diff
changeset
|
797 */ |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22365
diff
changeset
|
798 |