Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

127
LINES

< > BotCompany Repo | #1028231 // LINECOMP Command Line v0.3

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 11335K of libraries. Click here for Pure Java version (7179L/48K).

!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", "");
  bool balancing = 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<S> 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.balancing = balancing;
      if (balancing) print("balancing mode");
      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())) + ")");
}

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: 745 / 2407
Version history: 57 change(s)
Referenced in: [show references]