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.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. partLen, err := strconv.ParseInt(os.Args[3], 10, 64)
  29. if err != nil {
  30. fmt.Println(err)
  31. return
  32. }
  33. startTime := time.Now()
  34. obj, err := cli.Object().Download(cdsapi.ObjectDownload{
  35. UserID: 1,
  36. ObjectID: 470790,
  37. Offset: 0,
  38. Length: &openLen,
  39. PartSize: partLen,
  40. })
  41. if err != nil {
  42. fmt.Println(err)
  43. return
  44. }
  45. fmt.Printf("Open time: %v\n", time.Since(startTime))
  46. startTime = time.Now()
  47. buf := make([]byte, readLen)
  48. _, err = io.ReadFull(obj.File, buf)
  49. fmt.Printf("Read time: %v\n", time.Since(startTime))
  50. if err != nil {
  51. fmt.Println(err)
  52. return
  53. }
  54. startTime = time.Now()
  55. obj.File.Close()
  56. fmt.Printf("Close time: %v\n", time.Since(startTime))
  57. }
  58. func test2(url string) {
  59. cli := cdsapi.NewClient(&cdsapi.Config{
  60. URL: url,
  61. })
  62. obj, err := cli.Object().Download(cdsapi.ObjectDownload{
  63. UserID: 1,
  64. ObjectID: 27151,
  65. Offset: 0,
  66. PartSize: 100000000,
  67. // Length: &openLen,
  68. })
  69. if err != nil {
  70. fmt.Println(err)
  71. return
  72. }
  73. f, err := os.Create("test.txt")
  74. if err != nil {
  75. fmt.Println(err)
  76. return
  77. }
  78. io.Copy(f, obj.File)
  79. }