mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 08:10:55 +00:00
windows快速分配
This commit is contained in:
1 parent
3215955056
commit
63210dce63
6 files changed
+142
-14
No files matched your search
+28
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/monkeyWie/gopeed-core/download"
|
||||
"github.com/monkeyWie/gopeed-core/download/common"
|
||||
"github.com/monkeyWie/gopeed-core/download/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
downloader := buildDownloader()
|
||||
res, err := downloader.Resolve(&common.Request{
|
||||
URL: "http://192.168.200.163:8088/docker-compose",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = downloader.Create(res, &common.Options{
|
||||
Path: "E:\\test\\gopeed\\http",
|
||||
Connections: 4,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func buildDownloader() *download.Downloader {
|
||||
return download.NewDownloader(&http.Fetcher{BaseFetcher: &common.BaseFetcher{}})
|
||||
}
|
||||
@@ -48,6 +48,10 @@ type Process interface {
|
||||
Delete() error
|
||||
}
|
||||
|
||||
type FileCreator interface {
|
||||
Create(name string, size int64) (file *os.File, err error)
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
Files map[string]*os.File
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package file_allocate
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type FileAllocate interface {
|
||||
Allocate(name string, size int64) (file *os.File, err error)
|
||||
}
|
||||
|
||||
type DefaultFileAllocator struct {
|
||||
}
|
||||
|
||||
func (p *DefaultFileAllocator) Allocate(name string, size int64) (file *os.File, err error) {
|
||||
err = os.Truncate(name, size)
|
||||
file, err = os.OpenFile(name, os.O_RDWR, 0644)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package file_allocate
|
||||
|
||||
import "os"
|
||||
|
||||
type PreFileAllocator struct {
|
||||
}
|
||||
|
||||
func (p *PreFileAllocator) Allocate(name string, size int64) (file *os.File, err error) {
|
||||
err = os.Truncate(name, size)
|
||||
file, err = os.OpenFile(name, os.O_RDWR, 0644)
|
||||
return
|
||||
}
|
||||
@@ -48,6 +48,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
|
||||
@@ -1,23 +1,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"github.com/monkeyWie/gopeed-core/protocol/http"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procSetFileValidData = modkernel32.NewProc("SetFileValidData")
|
||||
)
|
||||
|
||||
func main() {
|
||||
request := &http.Request{
|
||||
Method: "get",
|
||||
URL: "http://github.com/proxyee-down-org/proxyee-down/releases/download/3.4/proxyee-down-main.jar",
|
||||
Header: map[string]string{
|
||||
"Host": "github.com",
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
|
||||
"Referer": "http://github.com/proxyee-down-org/proxyee-down/releases",
|
||||
"Accept-Encoding": "gzip, deflate, br",
|
||||
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||
},
|
||||
var err error
|
||||
name := "d:/test.data"
|
||||
var size int64 = 1024 * 1024 * 1024 * 4
|
||||
|
||||
err = os.Truncate(name, size)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
got, _ := http.Resolve(request)
|
||||
fmt.Println(got)
|
||||
|
||||
var hwnd HWND
|
||||
|
||||
err = ShellExecute(hwnd,
|
||||
"runas",
|
||||
"fsutil.exe",
|
||||
"file setValidData d:\\test.data 4294967296",
|
||||
"d:\\",
|
||||
syscall.SW_HIDE)
|
||||
|
||||
//err = exec.Command("fsutil", "file", "setValidData", "d:\\test.data", "4294967296").Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
file, _ := os.OpenFile(name, os.O_RDWR, 0644)
|
||||
defer os.Remove(name)
|
||||
defer file.Close()
|
||||
defer func() {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Println("输入回车结束")
|
||||
reader.ReadString('\n')
|
||||
}()
|
||||
|
||||
/*process, err := syscall.GetCurrentProcess()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var token syscall.Token
|
||||
err = syscall.OpenProcessToken(process, syscall.TOKEN_ADJUST_PRIVILEGES|syscall.TOKEN_QUERY, &token)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
||||
_, _, en := syscall.Syscall(procSetFileValidData.Addr(), 2, file.Fd(), uintptr(size), 0)
|
||||
if en != 0 {
|
||||
fmt.Println(en)
|
||||
return
|
||||
}*/
|
||||
|
||||
buf := []byte{1, 2, 3, 4, 5, 6, 7, 8}
|
||||
var (
|
||||
tm int64
|
||||
)
|
||||
|
||||
tm = time.Now().UnixNano()
|
||||
_, err = file.WriteAt(buf, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("write use:%d\n", toMill(time.Now().UnixNano()-tm))
|
||||
|
||||
tm = time.Now().UnixNano()
|
||||
_, err = file.WriteAt(buf, 1024*1024*1024*2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("write use:%d\n", toMill(time.Now().UnixNano()-tm))
|
||||
}
|
||||
|
||||
func toMill(nano int64) int64 {
|
||||
return nano / int64(time.Millisecond)
|
||||
}
|
||||
Reference in new issue
Block a user