You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "os"
  6. "strconv"
  7. "time"
  8. "gitlink.org.cn/cloudream/common/sdks/storage/cdsapi"
  9. )
  10. func main() {
  11. test1("http://121.36.5.116:32010")
  12. // test2("http://127.0.0.1:7890")
  13. }
  14. func test1(url string) {
  15. cli := cdsapi.NewClient(&cdsapi.Config{
  16. URL: url,
  17. })
  18. openLen, err := strconv.ParseInt(os.Args[1], 10, 64)
  19. if err != nil {
  20. fmt.Println(err)
  21. return
  22. }
  23. readLen, err := strconv.ParseInt(os.Args[2], 10, 64)
  24. if err != nil {
  25. fmt.Println(err)
  26. return
  27. }
  28. startTime := time.Now()
  29. obj, err := cli.Object().Download(cdsapi.ObjectDownload{
  30. UserID: 1,
  31. ObjectID: 470790,
  32. Offset: 0,
  33. Length: &openLen,
  34. })
  35. if err != nil {
  36. fmt.Println(err)
  37. return
  38. }
  39. fmt.Printf("Open time: %v\n", time.Since(startTime))
  40. startTime = time.Now()
  41. buf := make([]byte, readLen)
  42. _, err = io.ReadFull(obj.File, buf)
  43. fmt.Printf("Read time: %v\n", time.Since(startTime))
  44. if err != nil {
  45. fmt.Println(err)
  46. return
  47. }
  48. startTime = time.Now()
  49. obj.File.Close()
  50. fmt.Printf("Close time: %v\n", time.Since(startTime))
  51. }
  52. func test2(url string) {
  53. cli := cdsapi.NewClient(&cdsapi.Config{
  54. URL: url,
  55. })
  56. obj, err := cli.Object().Download(cdsapi.ObjectDownload{
  57. UserID: 1,
  58. ObjectID: 27151,
  59. Offset: 0,
  60. // Length: &openLen,
  61. })
  62. if err != nil {
  63. fmt.Println(err)
  64. return
  65. }
  66. f, err := os.Create("test.txt")
  67. if err != nil {
  68. fmt.Println(err)
  69. return
  70. }
  71. io.Copy(f, obj.File)
  72. }