Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of UTF-8 filenames #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/ZipFile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Julia
"""
module ZipFile

import Base: read, read!, eof, write, flush, close, mtime, position, show, unsafe_write
import Base: read, read!, eof, write, flush, close, mtime, position, show, unsafe_write, Sys
using Printf

export read, read!, eof, write, close, mtime, position, show
Expand All @@ -58,6 +58,15 @@ const Deflate = UInt16(8)

const _Method2Str = Dict{UInt16,String}(Store => "Store", Deflate => "Deflate")

"Unicode filename flag"
const _UnicodeFlag = 0x800

"Version made by"
const _VersionMadeBy = (Sys.iswindows() ? 0x0a00 : 0x0300) | _ZipVersion

"Default external file attributes: -rw-r-----"
const _DefaultExtFileAttr = Sys.iswindows() ? 0 : (UInt32(0o640) << 16)

mutable struct ReadableFile <: IO
_io :: IO
name :: String # filename
Expand Down Expand Up @@ -366,9 +375,9 @@ function flush(w::Writer)
# write central directory record
for f in w.files
_writele(w._io, UInt32(_CentralDirSig))
_writele(w._io, UInt16(_VersionMadeBy))
_writele(w._io, UInt16(_ZipVersion))
_writele(w._io, UInt16(_ZipVersion))
_writele(w._io, UInt16(0))
_writele(w._io, UInt16(_UnicodeFlag))
_writele(w._io, UInt16(f.method))
_writele(w._io, UInt16(f.dostime))
_writele(w._io, UInt16(f.dosdate))
Expand All @@ -381,7 +390,7 @@ function flush(w::Writer)
_writele(w._io, UInt16(0))
_writele(w._io, UInt16(0))
_writele(w._io, UInt16(0))
_writele(w._io, UInt32(0))
_writele(w._io, UInt32(_DefaultExtFileAttr))
_writele(w._io, UInt32(f._offset))
_writele(w._io, b)
cdsize += 46+length(b)
Expand Down Expand Up @@ -563,7 +572,7 @@ function addfile(w::Writer, name::AbstractString; method::Integer=Store, mtime::
# Write local file header. Missing entries will be filled in later.
_writele(w._io, UInt32(_LocalFileHdrSig))
_writele(w._io, UInt16(_ZipVersion))
_writele(w._io, UInt16(0))
_writele(w._io, UInt16(_UnicodeFlag))
_writele(w._io, UInt16(f.method))
_writele(w._io, UInt16(f.dostime))
_writele(w._io, UInt16(f.dosdate))
Expand Down