https://github.com/hslam/copyfilerange
Package copyfilerange wraps the copy_file_range system call.
https://github.com/hslam/copyfilerange
copy-file-range copyfilerange go golang
Last synced: about 1 year ago
JSON representation
Package copyfilerange wraps the copy_file_range system call.
- Host: GitHub
- URL: https://github.com/hslam/copyfilerange
- Owner: hslam
- License: mit
- Created: 2023-11-14T19:30:54.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-14T20:31:40.000Z (over 2 years ago)
- Last Synced: 2023-11-16T10:01:21.229Z (over 2 years ago)
- Topics: copy-file-range, copyfilerange, go, golang
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# copyfilerange
[](https://pkg.go.dev/github.com/hslam/copyfilerange)
[](https://github.com/hslam/copyfilerange/actions)
[](https://codecov.io/gh/hslam/copyfilerange)
[](https://goreportcard.com/report/github.com/hslam/copyfilerange)
[](https://github.com/hslam/copyfilerange/blob/master/LICENSE)
Package copyfilerange wraps the copy_file_range system call.
## Get started
### Install
```
go get github.com/hslam/copyfilerange
```
### Import
```
import "github.com/hslam/copyfilerange"
```
### Usage
#### Example
```go
package main
import (
"fmt"
"github.com/hslam/copyfilerange"
"os"
)
func main() {
srcName, dstName := "srcFile", "dstFile"
srcFile, _ := os.Create(srcName)
defer os.Remove(srcName)
defer srcFile.Close()
dstFile, _ := os.Create(dstName)
defer os.Remove(dstName)
defer dstFile.Close()
content := []byte("Hello world")
srcOffset, dstOffset := int64(64), int64(32)
srcFile.Truncate(srcOffset)
srcFile.WriteAt(content, srcOffset)
dstFile.Truncate(dstOffset + int64(len(content)))
roff, woff := srcOffset, dstOffset
copyfilerange.CopyFileRange(int(srcFile.Fd()), &roff, int(dstFile.Fd()), &woff, len(content), 0)
buf := make([]byte, len(content))
dstFile.ReadAt(buf, dstOffset)
fmt.Println(string(buf))
}
```
### Output
```
Hello world
```
### License
This package is licensed under a MIT license (Copyright (c) 2023 Meng Huang)
### Author
copyfilerange was written by Meng Huang.