Skip to content

Instantly share code, notes, and snippets.

@tyochiai
Last active May 4, 2020 06:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyochiai/239c5433872e4c9cb517 to your computer and use it in GitHub Desktop.
Save tyochiai/239c5433872e4c9cb517 to your computer and use it in GitHub Desktop.
ShiftJIS -> EUC-JP by golang
package conversion
import (
"io"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
)
//Conversion
func Conversion(inStream io.Reader, outStream io.Writer) error {
//read from stream (Shift-JIS to UTF-8)
transform.NewReader(inStream, japanese.ShiftJIS.NewDecoder())
//write to stream (UTF-8 to EUC-JP)
transform.NewWriter(outStream, japanese.EUCJP.NewEncoder())
//copy
if _, err := io.Copy(writer, reader); err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment