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

24
LINES

< > BotCompany Repo | #1008861 // zipFileSnippetToLazyTextMap_subfolder - reads all file names instantly (keys), loads values lazily (file contents)

JavaX fragment (include)

sbool zipFileSnippetToLazyTextMap_subfolder_debug;

// keeps file open until you cleanUp() the map
static SS zipFileSnippetToLazyTextMap_subfolder(S snippetID, S folderName) ctex {
  if (empty(folderName)) ret zipFileSnippetToLazyTextMap(snippetID);
  fS prefix = addSlash(folderName);
  final ZipFile zip = new ZipFile(loadLibrary(snippetID));
  O f = func(S name) {
    if (zipFileSnippetToLazyTextMap_subfolder_debug)
      print("subfolder get " + prefix+name);
    ret loadTextFileFromZipFile(zip, prefix + name);
  };
  ret autoCleanUp(new LazyValueTreeMap(startingWith_dropPrefix(listFilesInZip(zip), prefix), f) {
    public void finalize() ctex {
      cleanMeUp();
    }
    
    void cleanMeUp() {
      if (zipFileSnippetToLazyTextMap_subfolder_debug)
        print("subfolder cleanup");
      pcall-silent { zip.close(); }
    }
  });
}

Author comment

Began life as a copy of #1008856

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: #1008861
Snippet name: zipFileSnippetToLazyTextMap_subfolder - reads all file names instantly (keys), loads values lazily (file contents)
Eternal ID of this version: #1008861/8
Text MD5: d1f2bcee5443f867dd5547b005a2b96c
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-01 04:30:26
Source code size: 872 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 434 / 475
Version history: 7 change(s)
Referenced in: [show references]