Skip to content

Commit

Permalink
fsutil: fix something
Browse files Browse the repository at this point in the history
  • Loading branch information
3JoB committed Mar 17, 2023
1 parent 611481e commit 70a5a1c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"tidwall",
"twofish",
"ulib",
"ulibw",
"ulibws",
"zstd"
]
}
26 changes: 22 additions & 4 deletions fsutil/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ func Benchmark_Ulib_Write(b *testing.B) {
for i := 0; i < b.N; i++ {
fsutil.Write("test.ulib.io", "What fuck????")
}
fsutil.Remove("test.ulib.io")
if err := fsutil.Remove("test.ulib.io"); err != nil {
panic(err)
}
}

func Benchmark_UlibWriter_Write(b *testing.B) {
Expand All @@ -21,7 +23,21 @@ func Benchmark_UlibWriter_Write(b *testing.B) {
w.Add("test.ulibw.io")
}
w.Close()
fsutil.Remove("test.ulibw.io")
if err := fsutil.Remove("test.ulibw.io"); err != nil {
panic(err)
}
}

func Benchmark_UlibWriter_Strings_Write(b *testing.B) {
b.ResetTimer()
w, _ := fsutil.NewWriter("test.ulibws.io")
for i := 0; i < b.N; i++ {
w.AddString("test.ulibws.io")
}
w.Close()
if err := fsutil.Remove("test.ulibws.io"); err != nil {
panic(err)
}
}

func Benchmark_Basic_Write(b *testing.B) {
Expand All @@ -31,5 +47,7 @@ func Benchmark_Basic_Write(b *testing.B) {
f.Write([]byte("What fuck????"))
}
f.Close()
fsutil.Remove("test.basic.io")
}
if err := fsutil.Remove("test.basic.io"); err != nil {
panic(err)
}
}
4 changes: 2 additions & 2 deletions fsutil/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const (
)

type HashOpt struct {
HMACKey string
Crypt int
HMACKey string
Crypt int
}

func New(path string, opt *HashOpt) string {
Expand Down
12 changes: 10 additions & 2 deletions fsutil/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type nn struct {
os *os.File
os *os.File
writer *bufio.Writer
}

Expand All @@ -35,6 +35,14 @@ func (n *nn) Add(w any) (err error) {
return
}

func (n *nn) AddBytes(w []byte) error {
return n.addBytes(w)
}

func (n *nn) AddString(w string) error {
return n.addString(w)
}

func (n *nn) addAny(w any) error {
n.writer.Write(unsafeConvert.BytesReflect(w.(string)))
return nil
Expand All @@ -59,4 +67,4 @@ func (n *nn) Close() error {
}
n.os = nil
return nil
}
}
2 changes: 1 addition & 1 deletion hex/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// EncodeToString returns the hexadecimal encoding of src.
func EncodeToString(src []byte) string {
dst := make([]byte, len(src) * 2)
dst := make([]byte, len(src)*2)
hex.Encode(dst, src)
return unsafeConvert.StringReflect(dst)
}
Expand Down

0 comments on commit 70a5a1c

Please sign in to comment.