!7 set flag LeanMode. do not include function load. p { try { go(asList(args)); } catch e { //print(exceptionToStringShort(e)); printStackTrace(e); } } svoid go(LS args) { bool verbose; //print(+args); // javax still swallowing -v!? S cmd = popFirst(args); bool byteMode = contains(cmd, "b"); cmd = replace(cmd, "b", ""); if (eqOneOf(first(args), "-v", "-verbose", "-V")) { args = dropFirst(args); set verbose; } S archiveName = first(args); if (eqic(cmd, "x")) { print("Extracting"); if (empty(archiveName)) fail("Need archive name as second argument"); File f = newFile(archiveName); if (!fileExists(f)) fail("File not found: " + f.getAbsolutePath()); // TODO: byteMode LineCompReader lcr = new(f); LS filesToExtract = dropFirst(args); if (empty(filesToExtract)) { for (S version : lcr.versions()) extractVersion(lcr, version); } else { for (S name : filesToExtract) if (!lcr.versions().contains(name)) print("Warning: File " + name + " not found in archive"); else extractVersion(lcr, name); } } else if (eqic(cmd, "c")) { //print("Creating"); if (empty(archiveName)) fail("Need archive name as second argument"); LS filesToAdd = dropFirst(args); if (empty(filesToAdd)) fail("Please specify files to add to archive"); new LinkedHashMap data; for (S file : filesToAdd) { File f = newFile(file); if (!isFile(f)) print("Warning: File " + f.getAbsolutePath() + " not found, skipping"); else { print("Adding file " + file); data.put(file, bytesToString_raw(loadBinaryFile(f))); } } print("Compressing a total of " + nBytes(totalStringLength(values(data))) + "..."); time "Compression done" { new LineCompCompressor compressor; compressor.byteMode = byteMode; if (byteMode) print("byte mode"); compressor.verboseCompressionSteps = print(+verbose); compressor.verify = false; compressor.verboseStats = true; compressor.loadTexts(data); compressor.run(); File archiveFile = newFile(archiveName); saveGZTextFile(archiveFile, compressor.asText(), "ISO-8859-1"); } listArchive(archiveFile, false); } else if (eqic(cmd, "t")) { //print("Listing"); if (empty(archiveName)) fail("Need archive name as second argument"); File f = newFile(archiveName); if (!fileExists(f)) fail("File not found: " + f.getAbsolutePath()); listArchive(f, true); } else { print(autoUnindent_mls([[ This is LINECOMP v0.3, a supercompressor for a bunch of similar text files with fast extraction of any file. (c) Stefan Reich 2020, info@BotCompany.de. Source: https://code.BotCompany.de/1028231 Commands: c archive.lc textFile1 textFile2 ... - create LINECOMP archive archive.lc from files x archive.lc - extract archive.lc to current directory x archive.lc textFile1 - extract textFile1 from archive.lc to current directory t archive.lc - show contents of archive.lc ]])); } } svoid extractVersion(LineCompReader lcr, S version) { File outFile = newFile(version); saveBinaryFileVerbose(outFile, stringToBytes_raw(lcr.getText(version))); } svoid listArchive(File f, bool listFiles) ctex { LineCompReader lcr = new(f); if (listFiles) for (S version : lcr.versions()) print(" Found file: " + version //+ " (" + nLines(lcr.lineCountForVersion(version)) + ")"); + " (" + nBytes(lcr.byteCountForVersion(version)) + ")"); printWithPrecedingNL("Archive " + f.getCanonicalPath() + " stats:"); print(" " + str_toK_noSpace(lcr.totalByteCount()) + " of text compressed into " + str_toK_noSpace(l(f)) + " (" + nFiles(l(lcr.versions())) + ")"); }