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.

fromto.go 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package ioswitch
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  4. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  5. )
  6. type From interface {
  7. GetDataIndex() int
  8. }
  9. type To interface {
  10. // To所需要的文件流的范围。具体含义与DataIndex有关系:
  11. // 如果DataIndex == -1,则表示在整个文件的范围。
  12. // 如果DataIndex >= 0,则表示在文件的某个分片的范围。
  13. GetRange() exec.Range
  14. GetDataIndex() int
  15. }
  16. type FromTos []FromTo
  17. type FromTo struct {
  18. Froms []From
  19. Toes []To
  20. }
  21. func NewFromTo() FromTo {
  22. return FromTo{}
  23. }
  24. func (ft *FromTo) AddFrom(from From) *FromTo {
  25. ft.Froms = append(ft.Froms, from)
  26. return ft
  27. }
  28. func (ft *FromTo) AddTo(to To) *FromTo {
  29. ft.Toes = append(ft.Toes, to)
  30. return ft
  31. }
  32. type FromDriver struct {
  33. Handle *exec.DriverWriteStream
  34. DataIndex int
  35. }
  36. func NewFromDriver(dataIndex int) (*FromDriver, *exec.DriverWriteStream) {
  37. handle := &exec.DriverWriteStream{
  38. RangeHint: &exec.Range{},
  39. }
  40. return &FromDriver{
  41. Handle: handle,
  42. DataIndex: dataIndex,
  43. }, handle
  44. }
  45. func (f *FromDriver) GetDataIndex() int {
  46. return f.DataIndex
  47. }
  48. type FromNode struct {
  49. FileHash string
  50. Node *cdssdk.Node
  51. DataIndex int
  52. }
  53. func NewFromNode(fileHash string, node *cdssdk.Node, dataIndex int) *FromNode {
  54. return &FromNode{
  55. FileHash: fileHash,
  56. Node: node,
  57. DataIndex: dataIndex,
  58. }
  59. }
  60. func (f *FromNode) GetDataIndex() int {
  61. return f.DataIndex
  62. }
  63. type ToDriver struct {
  64. Handle *exec.DriverReadStream
  65. DataIndex int
  66. Range exec.Range
  67. }
  68. func NewToDriver(dataIndex int) (*ToDriver, *exec.DriverReadStream) {
  69. str := exec.DriverReadStream{}
  70. return &ToDriver{
  71. Handle: &str,
  72. DataIndex: dataIndex,
  73. }, &str
  74. }
  75. func NewToExecutorWithRange(dataIndex int, rng exec.Range) (*ToDriver, *exec.DriverReadStream) {
  76. str := exec.DriverReadStream{}
  77. return &ToDriver{
  78. Handle: &str,
  79. DataIndex: dataIndex,
  80. Range: rng,
  81. }, &str
  82. }
  83. func (t *ToDriver) GetDataIndex() int {
  84. return t.DataIndex
  85. }
  86. func (t *ToDriver) GetRange() exec.Range {
  87. return t.Range
  88. }
  89. type ToNode struct {
  90. Node cdssdk.Node
  91. DataIndex int
  92. Range exec.Range
  93. FileHashStoreKey string
  94. }
  95. func NewToNode(node cdssdk.Node, dataIndex int, fileHashStoreKey string) *ToNode {
  96. return &ToNode{
  97. Node: node,
  98. DataIndex: dataIndex,
  99. FileHashStoreKey: fileHashStoreKey,
  100. }
  101. }
  102. func NewToNodeWithRange(node cdssdk.Node, dataIndex int, fileHashStoreKey string, rng exec.Range) *ToNode {
  103. return &ToNode{
  104. Node: node,
  105. DataIndex: dataIndex,
  106. FileHashStoreKey: fileHashStoreKey,
  107. Range: rng,
  108. }
  109. }
  110. func (t *ToNode) GetDataIndex() int {
  111. return t.DataIndex
  112. }
  113. func (t *ToNode) GetRange() exec.Range {
  114. return t.Range
  115. }
  116. // type ToStorage struct {
  117. // Storage cdssdk.Storage
  118. // DataIndex int
  119. // }
  120. // func NewToStorage(storage cdssdk.Storage, dataIndex int) *ToStorage {
  121. // return &ToStorage{
  122. // Storage: storage,
  123. // DataIndex: dataIndex,
  124. // }
  125. // }
  126. // func (t *ToStorage) GetDataIndex() int {
  127. // return t.DataIndex
  128. // }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。