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.
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.
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.
Index ¶
- Constants
- func CopyDir(from, to string) error
- func CreateRandomDir(path, prefix string) (string, error)
- func CreateRandomFileName(path, prefix string) (string, error)
- func EnsureDirExists(dir string) error
- func EnsureFileExists(fn string) error
- func GetRoot(path string) (string, string)
- func HashDir(path string, testFunc func(fi os.FileInfo) bool, recursive bool) (strutil.Hash, error)
- func IsDirEmpty(name string) (bool, error)
- func ListDir(dir string) []os.FileInfo
- func RemoveFiles(path string, testFunc func(path string, fi os.FileInfo) bool) error
- func UnzipToFolder(zipFile, destDir string) error
- func WriteTo(toPath string, in io.Reader) error
- func ZipCopy(zw *ZipWriter, zi ZipIterator, prefix string) error
- func ZipFolder(srcDir, destFile string, testFunc func(string) bool, recursive bool) error
- type MMFile
- type ZipIterator
- type ZipWriter
Constants ¶
const BlockSize = 4096
Variables ¶
This section is empty.
Functions ¶
func CreateRandomDir ¶
CreateRandomDir creates a randomly name directory in the path with prefix
func CreateRandomFileName ¶
CreateRandomFileName in the path with prefix, but without creating new file there
func EnsureDirExists ¶
EnsureDirExists checks whether the dir exists and creates the new one if it doesn't
func EnsureFileExists ¶ added in v0.13.0
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 ¶
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 ¶
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 ¶
IsDirEmpty returns weather the dir provided by the name is empty or not
func RemoveFiles ¶
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 ¶
UnzipToFolder unzips zipFile content into the destDir
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 ¶
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 ¶
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) Flush ¶ added in v0.17.0
Flush allows to sync the mapped file to the disk. The operation can be long, so should be called often
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 ¶
NewZipWriter returns new ZipWriter