Skip to content

Instantly share code, notes, and snippets.

@lzjluzijie
Created March 16, 2019 14:18
Show Gist options
  • Save lzjluzijie/088b8f11fca5a33f0be766cbd7970ede to your computer and use it in GitHub Desktop.
Save lzjluzijie/088b8f11fca5a33f0be766cbd7970ede to your computer and use it in GitHub Desktop.
GB18030 zip
package main
import (
"archive/zip"
"github.com/saintfish/chardet"
"golang.org/x/text/encoding/simplifiedchinese"
"log"
"os"
)
func main() {
path := os.Args[1]
r, err := zip.OpenReader(path)
if err != nil {
log.Fatal(err)
}
for _, f := range r.File {
rs, err := chardet.NewTextDetector().DetectAll([]byte(f.Name))
if err != nil {
panic(err)
}
g, err := simplifiedchinese.GB18030.NewDecoder().String(f.Name)
if err != nil {
panic(err)
}
log.Printf("%s: %s %v", f.Name,g, rs)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment