character encoding - Why file's name get messy using archive/zip in golang, linux? -
i'm using golang's standard package archive/zip wrap several files zipfile.
here code test:
package main import ( "archive/zip" "log" "os" ) func main() { archive, _ := os.create("/tmp/测试file.zip") w := zip.newwriter(archive) // add files archive. var files = []struct { name, body string }{ {"测试.txt", "test content: 测试"}, {"test.txt", "test content: test"}, } _, file := range files { f, err := w.create(file.name) if err != nil { log.fatal(err) } _, err = f.write([]byte(file.body)) if err != nil { log.fatal(err) } } err := w.close() if err != nil { log.fatal(err) } }
results:
zip file named 测试file.zip
under /tmp
expected.
after unzip
it, 2 files: test.txt
, ц╡ЛшпХ.txt
, , mess.
contents in both of 2 files normal expected.
why happen , how fix this?
this might issue unzip
not handling utf8 names properly. explicitly using chinese locale worked me:
$ lang=zh_zh unzip 测试file.zip archive: 测试file.zip inflating: 测试.txt inflating: test.txt $ cat *.txt test content: testtest content: 测试
Comments
Post a Comment