Warning: session_start(): open(/var/lib/php/sessions/sess_nrklr37qf28c8i9drbsff6qg37, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
set flag LeanMode.
do not include function load.
p {
noRegularGC();
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", "");
bool toUpper = contains(cmd, "u");
cmd = replace(cmd, "u", "");
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;
compressor.toUpper = toUpper;
if (byteMode) print("byte mode");
if (toUpper) print("toUpper mode");
compressor.verboseCompressionSteps = print(+verbose);
compressor.verify = false;
compressor.verboseStats = true;
compressor.loadTexts(data);
data = null;
compressor.run();
File archiveFile = newFile(archiveName);
lcSaveToFile(compressor, archiveFile);
}
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
cb archive.lc file1 file2 ... - create BYTECOMP archive [compress byte-by-byte]
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())) + ")");
}