ios

package
v1.0.51 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package ios 输入输出相关.

包括 ReadLine, ContainsReader, WalkDir.

Index

Examples

Constants

View Source
const (
	Kilo
	Meg
	Giga
	Tera
	Peta
	Exa
)

Variables

View Source
var (
	ErrTimeout   = errors.New("time out")
	ErrChanClose = errors.New("channel close")
)

Functions

func NewWriter added in v0.2.19

func NewWriter(file string) (io.WriteCloser, error)

NewWriter 新建Writer,file存在Seek末尾,不存在创建.

func Read added in v1.0.49

func Read[E any](source <-chan E) (E, error)

Read 读取管道.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/ios"
)

func main() {
	data := make(chan int, 1)

	data <- 1
	fmt.Println(ios.Read(data))
	close(data)
	fmt.Println(ios.Read(data))

}
Output:

1 <nil>
0 channel close

func ReadLine

func ReadLine(file string, call func(line string) error) error

func ReadTimeout added in v1.0.49

func ReadTimeout[E any](source <-chan E, timeout time.Duration) (E, error)

Read 限制时间内读取管道.

func ReaderLine

func ReaderLine(reader io.Reader, call func(line string) error) error

func Unit added in v0.5.41

func Unit(size int64, prec int) string
Example
package main

import (
	"fmt"

	"github.com/xuender/oils/ios"
)

func main() {
	fmt.Println(ios.Unit(1, 2))
	fmt.Println(ios.Unit(100, 2))
	fmt.Println(ios.Unit(1024, 2))
	fmt.Println(ios.Unit(1700, 2))
	fmt.Println(ios.Unit(3*ios.Meg, 2))

}
Output:

1B
100B
1KB
1.7KB
3MB

func WalkDir

func WalkDir(root string, walkDirFunc fs.WalkDirFunc, level int) error

func Write added in v1.0.49

func Write[E any](data E, target chan<- E) (err error)

Write 返回管道写入是否失败.

Example
package main

import (
	"fmt"

	"github.com/xuender/oils/ios"
)

func main() {
	data := make(chan int, 2)
	fmt.Println(ios.Write(1, data))
	close(data)
	fmt.Println(ios.Write(1, data))

}
Output:

<nil>
channel close

func WriteTimeout added in v1.0.49

func WriteTimeout[E any](data E, target chan<- E, timeout time.Duration) (err error)

WriteTimeout 返回管道写入是否失败.

Types

type ContainsReader

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

func NewContainsReader

func NewContainsReader(reader io.Reader, subslice []byte) *ContainsReader

func (*ContainsReader) Contains

func (p *ContainsReader) Contains() bool

func (*ContainsReader) Read

func (p *ContainsReader) Read(data []byte) (int, error)

type PassWriter added in v1.0.51

type PassWriter struct{}

func NewPassWriter added in v1.0.51

func NewPassWriter() *PassWriter

func (*PassWriter) Write added in v1.0.51

func (*PassWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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