files

package
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: Apache-2.0 Imports: 14 Imported by: 1

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 create the new one if it doesn't

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 added in v0.3.3

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 added in v0.3.3

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

NewMMFile creates new or open existing and maps a region with the size into map. The size region must be multiplied on BlockSize. If the file size doesn't exist, or its initial size is less than the mapped size provided the file physical size will be extended to the size. If the size is less than 0, than the mapping will try to be done to the actual file size.

func (*MMFile) Buffer added in v0.3.3

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

Buffer returns Mapped memory slice to be read and written.

func (*MMFile) Close added in v0.3.3

func (mmf *MMFile) Close() error

Close closes the mapped file

func (*MMFile) Grow added in v0.3.3

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

Grow allows to increase the mapped region to the newSize.

func (*MMFile) Size added in v0.3.3

func (mmf *MMFile) Size() int64

Size returns the size of mapped region

func (*MMFile) String added in v0.3.3

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