Cyril Roelandt <tipec...@gmail.com> skribis:

> On 07/22/2016 11:30 PM, Ludovic Courtès wrote:
>> This seems to suggest that this could be factorized somehow.  Maybe
>> unpack once and read the two files at once?
>
> The problem is that both files might not be there, and unzip will return
> a non-zero exit code if any of them is missing, so it seems easier to
> just run unzip twice. WDYT?

OK, I see.  Then what about adding a procedure like:

  (define (file-from-zip-archive archive file)
    "Return the contents of FILE from ARCHIVE as a string, or #f if FILE
  could not be found in ARCHIVE or extraction failed."
    ;; … invoke unzip in temporary dir, check return code, then:
    (call-with-input-file (string-append tempdir "/" file)
      get-string-all))

That would move the bits about exit codes and all that out of the main
logic.

WDYT?

Thanks,
Ludo’.

Reply via email to