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).

1  
srecord noeq Zip2Zip(File inZip, ZipOutputStream outZip) {
2  
  IPred<S> predicate;
3  
  File outFile;
4  
  bool ourOutputStream;
5  
  
6  
  *(File *inZip, File *outFile) { ourOutputStream = true; }
7  
  *(File *inZip, ZipOutputStream *outZip, IPred<S> *predicate) {}
8  
9  
  run {
10  
    if (outFile != null && outZip == null) {
11  
      outZip = zipOutputStream(outFile);
12  
      set ourOutputStream;
13  
    }
14  
    temp ourOutputStream ? outZip : null;
15  
    
16  
    temp ZipFile zipFile = new(inZip);
17  
    for (e : enumerationToIterator(zipFile.entries())) {
18  
      S name = e.getName();
19  
      print("Copying " + name);
20  
      ZipEntry e2 = new(name);
21  
      continue unless predicate == null || predicate.get(name);
22  
      e2.setSize(e.getSize());
23  
      outZip.putNextEntry(e2);
24  
      temp var in = zipFile.getInputStream(e); 
25  
      copyFileContents(e.getName(), in, outZip);
26  
    }
27  
  }
28  
  
29  
  swappable void copyFileContents(S fileName, InputStream in, OutputStream out) {
30  
    copyStream(in, out);
31  
  }
32  
}

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: 101 / 167
Version history: 3 change(s)
Referenced in: [show references]