Last active
May 4, 2020 06:58
-
-
Save tyochiai/239c5433872e4c9cb517 to your computer and use it in GitHub Desktop.
ShiftJIS -> EUC-JP by golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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