summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-12-27 10:46:48 -0800
committerAraq <rumpf_a@web.de>2011-12-27 10:46:48 -0800
commit0ad42bd0586ec6b7c8264a401748f05030e428ef (patch)
tree26294bd61a2ab69079f9bbb78e7009814f3e31ac /lib
parentb336bf4039f3bc428f0a6690bf448f1e0b447c4b (diff)
parentf0f904ac70abec7bbab2c00075c9c4148a9b5132 (diff)
downloadNim-0ad42bd0586ec6b7c8264a401748f05030e428ef.tar.gz
Merge pull request #81 from Amrykid/master
Various changes around 'koch update'
Diffstat (limited to 'lib')
-rwxr-xr-xlib/impure/zipfiles.nim25
-rwxr-xr-xlib/pure/osproc.nim9
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/impure/zipfiles.nim b/lib/impure/zipfiles.nim
index bdefc2c93..2f0be6b99 100755
--- a/lib/impure/zipfiles.nim
+++ b/lib/impure/zipfiles.nim
@@ -142,3 +142,28 @@ iterator walkFiles*(z: var TZipArchive): string =
   while i < num:
     yield $zip_get_name(z.w, i, 0'i32)
     inc(i)
+
+
+proc extractFile*(z: var TZipArchive, srcFile: string, dest: PStream) =
+  ## extracts a file from the zip archive 'z' to the destination stream.
+  var strm = getStream(z, srcFile)
+  while true:
+    if not strm.atEnd:
+        dest.write(strm.readStr(1))
+    else: break
+  dest.flush()
+  strm.close()
+
+proc extractFile*(z: var TZipArchive, srcFile: string, dest: string) =
+  ## extracts a file from the zip archive 'z' to the destination filename.
+  var file = newFileStream(dest, fmReadWrite)
+  extractFile(z, srcFile, file)
+  file.close()
+
+proc extractAll*(z: var TZipArchive, dest: string) =
+  ## extracts all files from archive 'z' to the destination directory.
+  for file in walkFiles(z):
+    extractFile(z, file, dest & "/" & extractFilename(file))
+
+   
+   
\ No newline at end of file
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index dc107b382..510dff232 100755
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -102,7 +102,7 @@ proc processID*(p: PProcess): int {.rtl, extern: "nosp$1".} =
   ## returns `p`'s process ID.
   return p.id
 
-proc waitForExit*(p: PProcess): int {.rtl, extern: "nosp$1".}
+proc waitForExit*(p: PProcess, timeout: int = -1): int {.rtl, extern: "nosp$1".}
   ## waits for the process to finish and returns `p`'s error code.
 
 proc peekExitCode*(p: PProcess): int
@@ -382,8 +382,9 @@ when defined(Windows) and not defined(useNimRtl):
     if running(p):
       discard TerminateProcess(p.FProcessHandle, 0)
 
-  proc waitForExit(p: PProcess): int =
-    discard WaitForSingleObject(p.FProcessHandle, Infinite)
+  proc waitForExit(p: PProcess, timeout: int = -1): int =
+    discard WaitForSingleObject(p.FProcessHandle, timeout)
+
     var res: int32
     discard GetExitCodeProcess(p.FProcessHandle, res)
     result = res
@@ -640,7 +641,7 @@ elif not defined(useNimRtl):
         if kill(-p.id, SIGKILL) != 0'i32: OSError()
     else: OSError()
 
-  proc waitForExit(p: PProcess): int =
+  proc waitForExit(p: PProcess, timeout: int = -1): int =
     #if waitPid(p.id, p.exitCode, 0) == int(p.id):
     # ``waitPid`` fails if the process is not running anymore. But then
     # ``running`` probably set ``p.exitCode`` for us. Since ``p.exitCode`` is