guzba / zippy

Pure Nim implementation of deflate, zlib, gzip and zip.
MIT License
246 stars 29 forks source link

write content directly into zip archive #71

Open bung87 opened 8 months ago

bung87 commented 8 months ago

Hi, I was trying to do something like code below Thanks for putting effort in this project.


proc addFile*(
  archive: ZipArchive, content: string, path: string
) {.raises: [IOError, OSError, ZippyError].} =
  ## Adds a single file to the archive.

  let (head, tail) = splitPath(path)
  if head.len > 0 and head notin archive.contents:
    archive.contents[(head & os.DirSep).toUnixPath()] =
      ArchiveEntry(kind: ekDirectory)
  archive.contents[path.toUnixPath()] = ArchiveEntry(
    kind: ekFile,
    contents: content,
    lastModified: getTime(),
    permissions: {},
  )