files

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0, Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright 2023 The acquirecloud Authors

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.

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.

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

View Source
const BlockSize = 4096

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(from, to string) error

CopyDir copies dir by path "from" to the dir by path "to"

func CreateRandomDir

func CreateRandomDir(path, prefix string) (string, error)

CreateRandomDir creates a randomly name directory in the path with prefix

func CreateRandomFileName

func CreateRandomFileName(path, prefix string) (string, error)

CreateRandomFileName in the path with prefix, but without creating new file there

func EnsureDirExists

func EnsureDirExists(dir string) error

EnsureDirExists checks whether the dir exists and creates the new one if it doesn't

func EnsureFileExists added in v0.13.0

func EnsureFileExists(fn string) error

EnsureFileExists checks whether the file exists and creates the new one if it doesn't. The function will create directories which don't exist in the file path

func GetRoot

func GetRoot(path string) (string, string)

GetRoot receives absolute or relative file name and returns first folder. examples: "" => "", "" "/" => "", "" "/abc" => "", "abc" "/abc/" => "abc", "" "/abc/def.js" => "abc", "def.js" "/abc/ddd/def.js" => "abc", "ddd/def.js" "abc/ddd/def.js" => "abc", "ddd/def.js"

func HashDir

func HashDir(path string, testFunc func(fi os.FileInfo) bool, recursive bool) (strutil.Hash, error)

HashDir calculates SHA256 for the whole dir context. Context is the file names and their data if recursive is true then the hash will be calculated for all sub-folders as well, otherwise only the files in path will be included, but all directories in path will be ignored.

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

IsDirEmpty returns weather the dir provided by the name is empty or not

func ListDir

func ListDir(dir string) []os.FileInfo

ListDir returns files and directories non-recursive (in the dir provided only)

func RemoveFiles

func RemoveFiles(path string, testFunc func(path string, fi os.FileInfo) bool) error

RemoveFiles by path if testFunc() returns true for the FileInfo. The function walks into the folders recursively and a folder could be removed if all files from the folder are removed as well. testFunc allows to control whether to check a folder or not...

func UnzipToFolder

func UnzipToFolder(zipFile, destDir string) error

UnzipToFolder unzips zipFile content into the destDir

func WriteTo

func WriteTo(toPath string, in io.Reader) error

WriteTo writes the in stream to the toPath

func ZipCopy

func ZipCopy(zw *ZipWriter, zi ZipIterator, prefix string) error

ZipCopy copy files from zi to zw adding the prefix name to each file from zi

func ZipFolder

func ZipFolder(srcDir, destFile string, testFunc func(string) bool, recursive bool) error

ZipFolder archives srcDir content into destFile. The testFunc allows to filter files. If it is provided it will be called for every found file to test whether it should be zipped(true) or not(false). The recursive param indicates whether sub-folders should be added recursively or not

Types

type MMFile

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

MMFile struct provides memory mapped file implementation

NOTE: the object is Read-Write go-routine safe. It means that the methods Read and Write could be called for not overlapping bytes regions from different go-routines at the same time, but not other methods for the object calls are allowed.

func NewMMFile

func NewMMFile(fname string, minSize int64) (*MMFile, error)

NewMMFile opens an existing file, and it maps a region with at least the minSize into map. If minSize is positive, then minSize must be multiplied on BlockSize. If the file size is less than the minSize, the file physical size will be extended to the minSize. if the existing file size is greater than minSize provided, the mapped region will be for the actual file size.

func (*MMFile) Buffer

func (mmf *MMFile) Buffer(offs int64, size int) ([]byte, error)

Buffer returns Mapped memory slice to be read and written.

func (*MMFile) Close

func (mmf *MMFile) Close() error

Close closes the mapped file

func (*MMFile) Flush added in v0.17.0

func (mmf *MMFile) Flush() error

Flush allows to sync the mapped file to the disk. The operation can be long, so should be called often

func (*MMFile) Grow

func (mmf *MMFile) Grow(newSize int64) (err error)

Grow allows to increase the mapped region to the newSize.

func (*MMFile) Size

func (mmf *MMFile) Size() int64

Size returns the size of mapped region

func (*MMFile) String

func (mmf *MMFile) String() string

type ZipIterator

type ZipIterator interface {
	io.Closer
	// Next returns the next *zip.File or nil, if there is no ones anymore
	Next() *zip.File
}

ZipIterator provides an access to zip.Files

func NewZipIterator

func NewZipIterator(zipFile string) (ZipIterator, error)

NewZipIterator returns the zipIterator for the zipFile provided

type ZipWriter

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

ZipWriter struct allows to write files into a new zip archive

func NewZipWriter

func NewZipWriter(zipFilename string) (*ZipWriter, error)

NewZipWriter returns new ZipWriter

func (*ZipWriter) Close

func (zw *ZipWriter) Close() error

Close implements io.Closer

func (*ZipWriter) Create

func (zw *ZipWriter) Create(fileName string) (io.Writer, error)

Create creates the new file writer

Jump to

Keyboard shortcuts

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