writer

package
v1.45.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

Benchmark

New

goos: windows
goarch: amd64
pkg: github.com/3JoB/ulib/fsutil/writer
cpu: 12th Gen Intel(R) Core(TM) i7-12700H
Benchmark_Ulib_Write-20                                 	    1772	    650801 ns/op	    4717 B/op	       4 allocs/op
Benchmark_Ulib_Lite_Write-20                            	    3265	    386735 ns/op	    4712 B/op	       4 allocs/op
Benchmark_UlibWriter_Write-20                           	  140640	      7806 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Lite_Write-20                      	  134116	      9836 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Strings_Write-20                   	  144152	      9308 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Strings_Lite_Write-20              	259474774	         4.815 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Write-20                         	  168164	      9195 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Lite_Write-20                    	  132193	      9450 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Strings_Write-20                 	  163704	      9435 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Strings_Lite_Write-20            	  366168	      2889 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_MaxBuffer_Strings_Write-20         	  140949	      9489 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_MaxBuffer_Strings_Lite_Write-20    	263471228	         4.541 ns/op	       0 B/op	       0 allocs/op
Benchmark_Basic_Write-20                                	 1226612	       961.0 ns/op	    6528 B/op	       1 allocs/op
Benchmark_Basic_Lite_Write-20                           	189490268	         6.090 ns/op	       1 B/op	       1 allocs/op
PASS
coverage: 63.0% of statements
ok  	github.com/3JoB/ulib/fsutil/writer	23.739s

Old

goos: windows
goarch: amd64
pkg: github.com/3JoB/ulib/fsutil/writer
cpu: Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
Benchmark_Ulib_Write-32                                 	    2554	    461757 ns/op	    4808 B/op	       4 allocs/op
Benchmark_Ulib_Lite_Write-32                            	    2606	    472146 ns/op	    4808 B/op	       4 allocs/op
Benchmark_UlibWriter_Write-32                           	   89488	     12976 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Lite_Write-32                      	  123360	     10497 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Strings_Write-32                   	  125884	     10036 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_Strings_Lite_Write-32              	95578688	        11.08 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Write-32                         	   96375	     10968 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Lite_Write-32                    	  126484	      9635 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Strings_Write-32                 	  128119	      9648 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibOSWriter_Strings_Lite_Write-32            	  395128	      2533 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_MaxBuffer_Strings_Write-32         	   82396	     12732 ns/op	       0 B/op	       0 allocs/op
Benchmark_UlibWriter_MaxBuffer_Strings_Lite_Write-32    	106982149	        11.07 ns/op	       0 B/op	       0 allocs/op
Benchmark_Basic_Write-32                                	  575473	      1933 ns/op	    6528 B/op	       1 allocs/op
Benchmark_Basic_Lite_Write-32                           	59480732	        20.30 ns/op	       1 B/op	       1 allocs/op
PASS
ok  	github.com/3JoB/ulib/fsutil/writer	23.202s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer added in v1.43.0

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer represents a type used for buffered writing with configurable buffer limits and support for various data types.

func NewWriter

func NewWriter(path string) (*Buffer, error)

NewWriter initializes and returns a new instance of Buffer with a buffered writer, writing to the specified file path. If the file cannot be opened or created, it returns an error.

func (*Buffer) Add added in v1.43.0

func (n *Buffer) Add(w any) (err error)

Add writes the provided data to the internal writer. It supports string, []byte, or other types convertible to string.

func (*Buffer) AddBytes added in v1.43.0

func (n *Buffer) AddBytes(w []byte) error

AddBytes writes the provided byte slice to the internal buffered writer and returns an error if the write fails.

func (*Buffer) AddString added in v1.43.0

func (n *Buffer) AddString(w string) error

AddString writes the provided string to the internal buffered writer and returns an error if the write operation fails.

func (*Buffer) Buffered added in v1.43.0

func (n *Buffer) Buffered() int

Buffered returns the number of bytes currently stored in the internal buffer of the writer.

func (*Buffer) Close added in v1.43.0

func (n *Buffer) Close() error

Close finalizes the buffered writing operations by flushing the buffer and closing the associated file. Returns an error if any fail.

func (*Buffer) CopyIn added in v1.43.0

func (n *Buffer) CopyIn(in io.Writer) (written int64, err error)

CopyIn flushes the internal buffer and copies data from the internal file to the provided Writer.

func (*Buffer) CopyTo added in v1.43.0

func (n *Buffer) CopyTo(to io.Reader) (written int64, err error)

CopyTo transfers data from the provided io.Reader to the internal buffered writer. Returns the number of bytes written and an error.

func (*Buffer) Flush added in v1.43.0

func (n *Buffer) Flush() error

Flush writes any buffered data to the underlying writer and clears the buffer. Returns an error if the flush fails.

func (*Buffer) MaxBuffer added in v1.43.0

func (n *Buffer) MaxBuffer(max int)

MaxBuffer sets the maximum buffer size for the internal buffered writer.

type Os added in v1.43.0

type Os struct {
	// contains filtered or unexported fields
}

Os represents a wrapper around an *os.File object for performing write operations.

func NewOSWriter added in v1.27.0

func NewOSWriter(path string) (*Os, error)

NewOSWriter creates and returns a new Os instance for writing to the specified file path with necessary permissions.

func (*Os) Add added in v1.43.0

func (n *Os) Add(w any) (err error)

Add writes the provided value to the underlying os. Supports string, byte slice, or defaults to string conversion.

func (*Os) AddBytes added in v1.43.0

func (n *Os) AddBytes(w []byte) error

AddBytes writes the provided byte slice to the underlying file and returns an error if the write operation fails.

func (*Os) AddString added in v1.43.0

func (n *Os) AddString(w string) error

AddString writes the given string to the underlying file and returns an error if the write operation fails.

func (*Os) Close added in v1.43.0

func (n *Os) Close() error

Close closes the underlying os.File associated with the Os instance and returns any error encountered.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL