utils

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockID

func BlockID(path string, index int) string

func EndsWithDot

func EndsWithDot(path string) bool

func GetOwnerGroup

func GetOwnerGroup(info os.FileInfo) (string, string)

func GetRandID added in v0.14.6

func GetRandID(randNum int) string

func GroupName

func GroupName(gid int) string

func HasAccess

func HasAccess(callerUid, callerGid, fileUid, fileGid uint32, perm uint32, mask uint32) bool

HasAccess tests if a caller can access a file with permissions `perm` in mode `mask`

func IfNotExist added in v0.14.5

func IfNotExist(err error) bool

func IsError

func IsError(err syscall.Errno) bool

func KeyHash

func KeyHash(s string) uint64

func LookupGroup

func LookupGroup(name string) int

func LookupUser

func LookupUser(name string) int

func Max

func Max(a, b int) int

func MaxUInt64

func MaxUInt64(a, b uint64) uint64

func Min

func Min(a, b int) int

func MinUInt32

func MinUInt32(a, b uint32) uint32

func MinUInt64

func MinUInt64(a, b uint64) uint64

func StatModeToFileMode

func StatModeToFileMode(mode int) os.FileMode

func ToSyscallErrno

func ToSyscallErrno(err error) syscall.Errno

err默认为syscall.Errno, 当不能转换时返回syscall.ENOTSUP

func UserName

func UserName(uid int) string

Types

type Buffer

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

Buffer is a buffer to read/write integers.

func FromBuffer

func FromBuffer(buf []byte) *Buffer

FromBuffer utility to create *Buffer

func NewBuffer

func NewBuffer(sz uint32) *Buffer

NewBuffer returns a buffer with sz number of bytes.

func NewNativeBuffer

func NewNativeBuffer(buf []byte) *Buffer

NewNativeBuffer utility to create *Buffer of given size with nativeEndian

func ReadBuffer

func ReadBuffer(buf []byte) *Buffer

ReadBuffer utility to create *Buffer from slice of bytes

func (*Buffer) Buffer

func (b *Buffer) Buffer() []byte

Buffer returns

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the bytes

func (*Buffer) Get

func (b *Buffer) Get(l int) []byte

Get returns `l` bytes from offset

func (*Buffer) Get16

func (b *Buffer) Get16() uint16

Get16 returns uint16

func (*Buffer) Get32

func (b *Buffer) Get32() uint32

Get32 returns uint32

func (*Buffer) Get64

func (b *Buffer) Get64() uint64

Get64 returns uint64

func (*Buffer) Get8

func (b *Buffer) Get8() uint8

Get8 returns uint8

func (*Buffer) HasMore

func (b *Buffer) HasMore() bool

HasMore checks if offset is less than length

func (*Buffer) Left

func (b *Buffer) Left() int

Left returns number of bytes after offset

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns length of buffer

func (*Buffer) Put

func (b *Buffer) Put(v []byte)

Put appends slice of byte to Buffer

func (*Buffer) Put16

func (b *Buffer) Put16(v uint16)

Put16 appends uint16 to Buffer

func (*Buffer) Put32

func (b *Buffer) Put32(v uint32)

Put32 appends uint32 to Buffer

func (*Buffer) Put64

func (b *Buffer) Put64(v uint64)

Put64 appends uint64 to Buffer

func (*Buffer) Put8

func (b *Buffer) Put8(v uint8)

Put8 appends uint8 to Buffer

func (*Buffer) Seek

func (b *Buffer) Seek(p int)

Seek seeks or sets offset to `p`

func (*Buffer) SetBytes

func (b *Buffer) SetBytes(buf []byte)

SetBytes initilizes the Buffer with BigEndian ordering

type LeakyBuf

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

func NewLeakyBuf

func NewLeakyBuf(bufSize, n int) *LeakyBuf

NewLeakyBuf creates a leaky buffer which can hold at most n buffer, each with bufSize bytes.

func (*LeakyBuf) Get

func (lb *LeakyBuf) Get() (b []byte)

Get returns a buffer from the leaky buffer or create a new buffer.

func (*LeakyBuf) Put

func (lb *LeakyBuf) Put(b []byte)

Put add the buffer into the free buffer pool for reuse. Panic if the buffer size is not the same with the leaky buffer's. This is intended to expose error usage of leaky buffer.

Jump to

Keyboard shortcuts

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