Move to gob.Encoder

pull/135/head
Pagran 5 years ago
parent e3bb6b1993
commit 4611407781

@ -6,10 +6,9 @@ package main
import (
"bufio"
"bytes"
"encoding/json"
"encoding/gob"
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
@ -49,8 +48,7 @@ type privateImports struct {
}
func appendPrivateNameMap(nameMap map[string]string, packageDirectory string) error {
mapFile := filepath.Join(packageDirectory, garbleMapFile)
data, err := ioutil.ReadFile(mapFile)
file, err := os.Open(filepath.Join(packageDirectory, garbleMapFile))
if errors.Is(err, os.ErrNotExist) {
return nil
}
@ -59,7 +57,7 @@ func appendPrivateNameMap(nameMap map[string]string, packageDirectory string) er
}
var localMap map[string]string
if err = json.Unmarshal(data, &localMap); err != nil {
if err = gob.NewDecoder(file).Decode(&localMap); err != nil {
return err
}

@ -600,12 +600,14 @@ func transformCompile(args []string) ([]string, error) {
if len(privateNameMap) > 0 {
outputDirectory := filepath.Dir(flagValue(flags, "-o"))
data, err := json.Marshal(privateNameMap)
file, err := os.Create(filepath.Join(outputDirectory, garbleMapFile))
if err != nil {
return nil, err
}
defer file.Close()
if err := ioutil.WriteFile(filepath.Join(outputDirectory, garbleMapFile), data, 0644); err != nil {
if err := gob.NewEncoder(file).Encode(privateNameMap); err != nil {
return nil, err
}
}

Loading…
Cancel
Save