title: Golang: Unzip files in Go gets char encoding problems in the files names when file has been zipped in windows
body: <p>I´m trying to unzip files in Go (Golang) using the zip lib. The problem is that when the zip file has been zipped in windows all special characters get messy.
  windows probably uses windows1252 char encoding. Just cant figure out how to unzip theses files.
  I´ve already tried to use the <code>golang.org/x/text/encoding/charmap</code> or <code>golang.org/x/text/transform</code>, but no luck.
  I guess, inside the zip lib should have an anternative to change the charmap.</p>
  <p>Another problem: sometimes the app will unzip files zipped on windows and sometimes zipped on a different OS. So, the app will need to identify the char encoding.</p>
  <p>This is the code (thanks to: <a href="https://golangcode.com/unzip-files-in-go/" rel="nofollow noreferrer">https://golangcode.com/unzip-files-in-go/</a>):</p>
  <pre><code>package main
  
  import (
      &quot;archive/zip&quot;
      &quot;fmt&quot;
      &quot;io&quot;
      &quot;log&quot;
      &quot;os&quot;
      &quot;path/filepath&quot;
      &quot;strings&quot;
  )
  
  func main() {
  
      files, err := Unzip(&quot;Edificações e Instalações Operacionais - 08.03 a 12.03.2021.zip&quot;, &quot;output-folder&quot;)
      if err != nil {
          log.Fatal(err)
      }
  
      fmt.Println(&quot;Unzipped:\n&quot; + strings.Join(files, &quot;\n&quot;))
  }
  
  // Unzip will decompress a zip archive, moving all files and folders
  // within the zip file (parameter 1) to an output directory (parameter 2).
  func Unzip(src string, dest string) ([]string, error) {
  
      var filenames []string
  
      r, err := zip.OpenReader(src)
      if err != nil {
          return filenames, err
      }
      defer r.Close()
  
      for _, f := range r.File {
  
          // Store filename/path for returning and using later on
          fpath := filepath.Join(dest, f.Name)
  
          
          if !strings.HasPrefix(fpath, filepath.Clean(dest)+string(os.PathSeparator)) {
              return filenames, fmt.Errorf(&quot;%s: illegal file path&quot;, fpath)
          }
  
          filenames = append(filenames, fpath)
  
          if f.FileInfo().IsDir() {
              // Make Folder
              os.MkdirAll(fpath, os.ModePerm)
              continue
          }
  
          // Make File
          if err = os.MkdirAll(filepath.Dir(fpath), os.ModePerm); err != nil {
              return filenames, err
          }
  
          outFile, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
          if err != nil {
              return filenames, err
          }
  
          rc, err := f.Open()
          if err != nil {
              return filenames, err
          }
  
          _, err = io.Copy(outFile, rc)
  
          // Close the file without defer to close before next iteration of loop
          outFile.Close()
          rc.Close()
  
          if err != nil {
              return filenames, err
          }
      }
      return filenames, nil
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/gs5zx.png" rel="nofollow noreferrer">This is The Output</a></p>