cleaned up various modules
This commit is contained in:
parent
4367fb26ad
commit
d4bc11b654
12 changed files with 65 additions and 64 deletions
|
|
@ -13,18 +13,18 @@ import
|
|||
streams, libzip, times, os
|
||||
|
||||
type
|
||||
TZipArchive* = object of TObject ## represents a zip archive
|
||||
mode: TFileMode
|
||||
TZipArchive* = object of RootObj ## represents a zip archive
|
||||
mode: FileMode
|
||||
w: PZip
|
||||
|
||||
|
||||
proc zipError(z: var TZipArchive) =
|
||||
var e: ref EIO
|
||||
var e: ref IOError
|
||||
new(e)
|
||||
e.msg = $zip_strerror(z.w)
|
||||
raise e
|
||||
|
||||
proc open*(z: var TZipArchive, filename: string, mode: TFileMode = fmRead): bool =
|
||||
proc open*(z: var TZipArchive, filename: string, mode: FileMode = fmRead): bool =
|
||||
## Opens a zip file for reading, writing or appending. All file modes are
|
||||
## supported. Returns true iff successful, false otherwise.
|
||||
var err, flags: int32
|
||||
|
|
@ -72,7 +72,7 @@ proc addFile*(z: var TZipArchive, file: string) =
|
|||
|
||||
proc mySourceCallback(state, data: pointer, len: int,
|
||||
cmd: TZipSourceCmd): int {.cdecl.} =
|
||||
var src = cast[PStream](state)
|
||||
var src = cast[Stream](state)
|
||||
case cmd
|
||||
of ZIP_SOURCE_OPEN:
|
||||
if src.setPositionImpl != nil: setPosition(src, 0) # reset
|
||||
|
|
@ -93,7 +93,7 @@ proc mySourceCallback(state, data: pointer, len: int,
|
|||
of constZIP_SOURCE_FREE: GC_unref(src)
|
||||
else: assert(false)
|
||||
|
||||
proc addFile*(z: var TZipArchive, dest: string, src: PStream) =
|
||||
proc addFile*(z: var TZipArchive, dest: string, src: Stream) =
|
||||
## Adds a file named with `dest` to the archive `z`. `dest`
|
||||
## may contain a path. The file's content is read from the `src` stream.
|
||||
assert(z.mode != fmRead)
|
||||
|
|
@ -107,14 +107,14 @@ proc addFile*(z: var TZipArchive, dest: string, src: PStream) =
|
|||
# -------------- zip file stream ---------------------------------------------
|
||||
|
||||
type
|
||||
TZipFileStream = object of TStream
|
||||
TZipFileStream = object of StreamObj
|
||||
f: PZipFile
|
||||
|
||||
PZipFileStream* =
|
||||
ref TZipFileStream ## a reader stream of a file within a zip archive
|
||||
|
||||
proc fsClose(s: PStream) = zip_fclose(PZipFileStream(s).f)
|
||||
proc fsReadData(s: PStream, buffer: pointer, bufLen: int): int =
|
||||
proc fsClose(s: Stream) = zip_fclose(PZipFileStream(s).f)
|
||||
proc fsReadData(s: Stream, buffer: pointer, bufLen: int): int =
|
||||
result = zip_fread(PZipFileStream(s).f, buffer, bufLen)
|
||||
|
||||
proc newZipFileStream(f: PZipFile): PZipFileStream =
|
||||
|
|
@ -144,7 +144,7 @@ iterator walkFiles*(z: var TZipArchive): string =
|
|||
inc(i)
|
||||
|
||||
|
||||
proc extractFile*(z: var TZipArchive, srcFile: string, dest: PStream) =
|
||||
proc extractFile*(z: var TZipArchive, srcFile: string, dest: Stream) =
|
||||
## extracts a file from the zip archive `z` to the destination stream.
|
||||
var strm = getStream(z, srcFile)
|
||||
while true:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue