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

32
LINES

< > BotCompany Repo | #1033498 // Zip2Zip

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4845L/27K).

srecord noeq Zip2Zip(File inZip, ZipOutputStream outZip) {
  IPred<S> predicate;
  File outFile;
  bool ourOutputStream;
  
  *(File *inZip, File *outFile) { ourOutputStream = true; }
  *(File *inZip, ZipOutputStream *outZip, IPred<S> *predicate) {}

  run {
    if (outFile != null && outZip == null) {
      outZip = zipOutputStream(outFile);
      set ourOutputStream;
    }
    temp ourOutputStream ? outZip : null;
    
    temp ZipFile zipFile = new(inZip);
    for (e : enumerationToIterator(zipFile.entries())) {
      S name = e.getName();
      print("Copying " + name);
      ZipEntry e2 = new(name);
      continue unless predicate == null || predicate.get(name);
      e2.setSize(e.getSize());
      outZip.putNextEntry(e2);
      temp var in = zipFile.getInputStream(e); 
      copyFileContents(e.getName(), in, outZip);
    }
  }
  
  swappable void copyFileContents(S fileName, InputStream in, OutputStream out) {
    copyStream(in, out);
  }
}

Author comment

Began life as a copy of #1001173

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033498
Snippet name: Zip2Zip
Eternal ID of this version: #1033498/4
Text MD5: 939bb164e8524f3360e964970cf57e30
Transpilation MD5: c44cf771219fe6ec9136788ebcb0bce4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-29 07:16:43
Source code size: 991 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 165 / 256
Version history: 3 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)