GithubHelp home page GithubHelp logo

zip-1's Introduction

zip

Wrapper for the zip library

Usage

zip

import zip/zipfiles
# Opens a zip file for reading, writing or appending.
var z: ZipArchive
  if not z.open(filename):
    echo "Opening zip failed"
    quit(1)

# extracts all files from archive z to the destination directory.
z.extractAll("files/td")

read and write using Stream

import zip/zipfiles
import streams
var z: ZipArchive
# add new file
z.open(filename, fmWrite)
z.addFile("foo.bar", newStringStream("content"))

# read file to string stream
z.open(filename, fmRead)
let outStream = newStringStream("")
z.extractFile("foo.bar", outStream)

load archive from memory

var z: ZipArchive
z.fromBuffer(archiveData)

zlib

import zip/zlib
uncompress(compress(text, stream=RAW_DEFLATE), stream=RAW_DEFLATE) 
uncompress(compress(text, stream=ZLIB_STREAM), stream=ZLIB_STREAM) 
uncompress(compress(text, stream=GZIP_STREAM), stream=GZIP_STREAM) 
uncompress(compress(text, stream=ZLIB_STREAM), stream=DETECT_STREAM) 
uncompress(compress(text, stream=GZIP_STREAM), stream=DETECT_STREAM) 
compress(text, stream=RAW_DEFLATE)
compress(text, stream=GZIP_STREAM)
compress(text, stream=ZLIB_STREAM)

gzip

import zip/gzipfiles
# read text data
let arch_gz = newGzFileStream("files/gzipfiletest.txt.gz").readAllAndClose()

read from archive and write to new archive.

let w = newGzFileStream("files/gzipfiletest.data.gz", fmWrite)
let chunk_size = 32
var num_bytes = text.len
var idx = 0
while true:
  w.writeData(text[idx].unsafeAddr, min(num_bytes, chunk_size))
  if num_bytes < chunk_size:
    break
  dec(num_bytes, chunk_size)
  inc(idx, chunk_size)
w.close()

read line by line confirming that behavior of atEnd is consistent with standard FileStream

let gzfs = newGzFileStream("files/gzipfiletest.txt.gz")
  while not gzfs.atEnd():
    discard gzfs.readLine()

zip-1's People

Contributors

alexisad avatar araq avatar ba0f3 avatar bung87 avatar dom96 avatar emekoi avatar karantin2020 avatar krux02 avatar lemonboy avatar markus-oberhumer avatar narimiran avatar nigredo-tori avatar parashurama avatar recloser avatar snej avatar vegansk avatar vklayd avatar yglukhov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.