Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
/ ZipWriter Public archive
forked from moteus/ZipWriter

Library for creating ZIP archive for Lua 5.1/5.2

License

Notifications You must be signed in to change notification settings

LuaDist/ZipWriter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9dca874 · Jun 8, 2014

History

69 Commits
Feb 17, 2014
Jun 17, 2013
Sep 27, 2012
Jun 8, 2014
Jun 16, 2013
Jun 6, 2014
Apr 24, 2013
Jun 7, 2014
Feb 17, 2014
Apr 11, 2013
Jun 6, 2014
Feb 17, 2014
Mar 24, 2014

Repository files navigation

##Library for creating ZIP archive for Lua 5.1/5.2.

Based on http://wiki.tcl.tk/15158

Build Status Coverage Status Licence

Dependences

  • lzlib
  • struct
  • bit32 or bit
  • iconv (if not found then file names passed as is)
  • alien/ffi (on Windos detect system default codepage)
  • lunitx (only for test)
  • [AesFileEncrypt] (https://github.com/moteus/lua-AesFileEncrypt) (optional)

Supports

  • write to non seekable stream
  • utf8 file names in archives (required iconv)
  • ZIP64 (does not use stream:seek())

Usage

Make simple archive

function make_reader(fname)
  local f = assert(io.open(fname, 'rb'))
  local chunk_size = 1024
  local desc = {
    istext   = true,
    isfile   = true,
    isdir    = false,
    mtime    = 1348048902, -- lfs.attributes('modification') 
    exattrib = 32,         -- get from GetFileAttributesA
    platform = 'fat32',    -- `exattrib` is platform dependent
  }
  return desc, desc.isfile and function()
    local chunk = f:read(chunk_size)
    if chunk then return chunk end
    f:close()
  end
end

local ZipWriter = require "ZipWriter"
ZipStream = ZipWriter.new()
ZipStream:open_stream( assert(io.open('readme.zip', 'w+b')), true )
ZipStream:write('README.md', make_reader('README.md'))
ZipStream:close()

Reading file from FTP and saving archive on FTP

local ZipWriter = require "ZipWriter"
local FTP = require "socket.ftp"

local ZipStream = ZipWriter.new()

-- write zip file directly to ftp
-- lua 5.1 needs coco
ZipStream:open_writer(ZipWriter.co_writer(function(reader)
  FTP.put{
    -- ftp params ...
    path = 'test.zip';
    src  = reader;
  }
end))

-- read from FTP
FTP.get{
  -- ftp params ...
  path = 'test.txt'
  sink = ZipWriter.sink(ZipStream, 'test.txt', {isfile=true;istext=1})
}

ZipStream:close()

Make encrypted archive

local ZipWriter  = require"ZipWriter"
local AesEncrypt = require"ZipWriter.encrypt.aes"

ZipStream = ZipWriter.new{
  encrypt = AesEncrypt.new('password')
}

-- as before

Bitdeli Badge

About

Library for creating ZIP archive for Lua 5.1/5.2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 100.0%