strex: added `detectUrl()`
[iv.d.git] / vfs / samples / mkziptest.d
blob3f938baa0a981d9ddda8ca136ae03f8958dd435b
1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module mkziptest /*is aliced*/;
19 import iv.alice;
20 import iv.strex;
21 import iv.vfs.io;
22 import iv.vfs.writers.zip;
25 void main (string[] args) {
26 auto method = ZipWriter.Method.Deflate;
28 for (usize idx = 1; idx < args.length;) {
29 string arg = args[idx];
30 if (arg == "--") {
31 import std.algorithm : remove;
32 args = args.remove(idx);
33 break;
35 if (arg.length == 0) {
36 import std.algorithm : remove;
37 args = args.remove(idx);
38 continue;
40 if (arg[0] == '-') {
41 switch (arg) {
42 case "--lzma": method = ZipWriter.Method.Lzma; break;
43 case "--store": method = ZipWriter.Method.Store; break;
44 case "--deflate": method = ZipWriter.Method.Deflate; break;
45 default: writeln("invalid argument: '", arg, "'"); throw new Exception("boom");
47 import std.algorithm : remove;
48 args = args.remove(idx);
49 continue;
51 ++idx;
54 if (args.length < 2) {
55 writeln("usage: mkziptest arc.zip [files...]");
56 throw new Exception("boom");
59 auto fo = VFile(args[1], "w");
61 auto zw = new ZipWriter(fo);
62 scope(failure) if (zw.isOpen) zw.abort();
64 if (args.length == 2) {
65 vfsRegister!"first"(new VFSDriverDiskListed(".", true)); // data dir, will be looked last
66 foreach (const ref de; vfsAllFiles()) {
67 if (de.name.endsWithCI(".zip")) continue;
68 writeln(de.name);
69 zw.pack(VFile(de.name), de.name, ZipFileTime(de.modtime), method);
71 } else {
72 foreach (string fname; args[2..$]) {
73 import std.file;
74 import std.datetime;
75 writeln(fname);
76 zw.pack(VFile(fname), fname, ZipFileTime(fname.timeLastModified.toUTC.toUnixTime()), method);
80 zw.finish();