Download Jar. Uses 11335K of libraries. Click here for Pure Java version (7179L/48K).
1 | !7 |
2 | |
3 | set flag LeanMode. |
4 | do not include function load. |
5 | |
6 | p { |
7 | noRegularGC(); |
8 | try { |
9 | go(asList(args)); |
10 | } catch e { |
11 | //print(exceptionToStringShort(e)); |
12 | printStackTrace(e); |
13 | } |
14 | } |
15 | |
16 | svoid go(LS args) { |
17 | bool verbose; |
18 | //print(+args); // javax still swallowing -v!? |
19 | S cmd = popFirst(args); |
20 | bool byteMode = contains(cmd, "b"); |
21 | cmd = replace(cmd, "b", ""); |
22 | bool toUpper = contains(cmd, "u"); |
23 | cmd = replace(cmd, "u", ""); |
24 | bool balancing = contains(cmd, "B"); |
25 | cmd = replace(cmd, "B", ""); |
26 | |
27 | if (eqOneOf(first(args), "-v", "-verbose", "-V")) { |
28 | args = dropFirst(args); |
29 | set verbose; |
30 | } |
31 | |
32 | S archiveName = first(args); |
33 | if (eqic(cmd, "x")) { |
34 | print("Extracting"); |
35 | if (empty(archiveName)) fail("Need archive name as second argument"); |
36 | |
37 | File f = newFile(archiveName); |
38 | if (!fileExists(f)) fail("File not found: " + f.getAbsolutePath()); |
39 | |
40 | // TODO: byteMode |
41 | LineCompReader lcr = new(f); |
42 | |
43 | LS filesToExtract = dropFirst(args); |
44 | if (empty(filesToExtract)) { |
45 | for (S version : lcr.versions()) |
46 | extractVersion(lcr, version); |
47 | } else { |
48 | for (S name : filesToExtract) |
49 | if (!lcr.versions().contains(name)) |
50 | print("Warning: File " + name + " not found in archive"); |
51 | else |
52 | extractVersion(lcr, name); |
53 | } |
54 | } else if (eqic(cmd, "c")) { |
55 | //print("Creating"); |
56 | if (empty(archiveName)) fail("Need archive name as second argument"); |
57 | LS filesToAdd = dropFirst(args); |
58 | if (empty(filesToAdd)) fail("Please specify files to add to archive"); |
59 | |
60 | new LinkedHashMap<S> data; |
61 | for (S file : filesToAdd) { |
62 | File f = newFile(file); |
63 | if (!isFile(f)) |
64 | print("Warning: File " + f.getAbsolutePath() + " not found, skipping"); |
65 | else { |
66 | print("Adding file " + file); |
67 | data.put(file, bytesToString_raw(loadBinaryFile(f))); |
68 | } |
69 | } |
70 | print("Compressing a total of " + nBytes(totalStringLength(values(data))) + "..."); |
71 | time "Compression done" { |
72 | new LineCompCompressor compressor; |
73 | compressor.byteMode = byteMode; |
74 | compressor.toUpper = toUpper; |
75 | if (byteMode) print("byte mode"); |
76 | if (toUpper) print("toUpper mode"); |
77 | compressor.verboseCompressionSteps = print(+verbose); |
78 | compressor.balancing = balancing; |
79 | if (balancing) print("balancing mode"); |
80 | compressor.verify = false; |
81 | compressor.verboseStats = true; |
82 | compressor.loadTexts(data); |
83 | data = null; |
84 | compressor.run(); |
85 | File archiveFile = newFile(archiveName); |
86 | lcSaveToFile(compressor, archiveFile); |
87 | } |
88 | |
89 | listArchive(archiveFile, false); |
90 | } else if (eqic(cmd, "t")) { |
91 | //print("Listing"); |
92 | if (empty(archiveName)) fail("Need archive name as second argument"); |
93 | File f = newFile(archiveName); |
94 | if (!fileExists(f)) fail("File not found: " + f.getAbsolutePath()); |
95 | |
96 | listArchive(f, true); |
97 | } else { |
98 | print(autoUnindent_mls([[ |
99 | This is LINECOMP v0.3, a supercompressor for a bunch of similar text files with fast extraction of any file. |
100 | (c) Stefan Reich 2020, info@BotCompany.de. Source: https://code.BotCompany.de/1028231 |
101 | |
102 | Commands: |
103 | |
104 | c archive.lc textFile1 textFile2 ... - create LINECOMP archive archive.lc from files |
105 | cb archive.lc file1 file2 ... - create BYTECOMP archive [compress byte-by-byte] |
106 | x archive.lc - extract archive.lc to current directory |
107 | x archive.lc textFile1 - extract textFile1 from archive.lc to current directory |
108 | t archive.lc - show contents of archive.lc |
109 | ]])); |
110 | } |
111 | } |
112 | |
113 | svoid extractVersion(LineCompReader lcr, S version) { |
114 | File outFile = newFile(version); |
115 | saveBinaryFileVerbose(outFile, stringToBytes_raw(lcr.getText(version))); |
116 | } |
117 | |
118 | svoid listArchive(File f, bool listFiles) ctex { |
119 | LineCompReader lcr = new(f); |
120 | if (listFiles) |
121 | for (S version : lcr.versions()) |
122 | print(" Found file: " + version |
123 | //+ " (" + nLines(lcr.lineCountForVersion(version)) + ")"); |
124 | + " (" + nBytes(lcr.byteCountForVersion(version)) + ")"); |
125 | printWithPrecedingNL("Archive " + f.getCanonicalPath() + " stats:"); |
126 | print(" " + str_toK_noSpace(lcr.totalByteCount()) + " of text compressed into " + str_toK_noSpace(l(f)) + " (" + nFiles(l(lcr.versions())) + ")"); |
127 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, mplzucoataeu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1028231 |
Snippet name: | LINECOMP Command Line v0.3 |
Eternal ID of this version: | #1028231/58 |
Text MD5: | d716c7c058a37f5613739d3d4c9150eb |
Transpilation MD5: | d08569d75fb7d86b20db55fe05991b41 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-23 19:23:54 |
Source code size: | 4403 bytes / 127 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 747 / 2412 |
Version history: | 57 change(s) |
Referenced in: | [show references] |