1 | // TODO: subdirectories |
2 | // Now sorts file list first (to ensure reproducable MD5 of zip) |
3 | static int dir2zip(File inDir, ZipOutputStream outZip, String outPrefix) ctex { |
4 | new L<File> files; |
5 | for (File f : inDir.listFiles()) |
6 | if (f.isFile()) |
7 | files.add(f); |
8 | |
9 | sortFilesByName(files); |
10 | for (File f : files) { |
11 | System.out.println("Copying " + f.getName()); |
12 | outZip.putNextEntry(new ZipEntry(outPrefix + f.getName())); |
13 | InputStream fin = new FileInputStream(f); |
14 | copyStream(fin, outZip); |
15 | fin.close(); |
16 | } |
17 | return files.size(); |
18 | } |
19 | |
20 | static int dir2zip(File inDir, ZipOutputStream outZip) { |
21 | return dir2zip(inDir, outZip, ""); |
22 | } |
23 | |
24 | static int dir2zip(String inDir, ZipOutputStream outZip) { |
25 | return dir2zip(new File(inDir), outZip, ""); |
26 | } |
27 | |
28 | static int dir2zip(File inDir, File zip, S outPrefix default "") ctex { |
29 | mkdirsForFile(zip); |
30 | FileOutputStream fout = new FileOutputStream(zip); |
31 | ZipOutputStream outZip = new ZipOutputStream(fout); |
32 | try { |
33 | ret dir2zip(inDir, outZip, outPrefix); |
34 | } finally { |
35 | outZip.close(); |
36 | } |
37 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001174 |
Snippet name: | dir2zip (no subdirectories - use dir2zip_recurse for that) |
Eternal ID of this version: | #1001174/2 |
Text MD5: | 0f540d087f2d5fb3eb9c8f40a6aeea3d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-04-28 14:58:39 |
Source code size: | 1086 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 786 / 996 |
Version history: | 1 change(s) |
Referenced in: | [show references] |