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 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package ioswitch2
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  4. "gitlink.org.cn/cloudream/common/utils/math2"
  5. clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
  6. )
  7. type From interface {
  8. GetStreamIndex() StreamIndex
  9. }
  10. type To interface {
  11. // To所需要的文件流的范围。具体含义与DataIndex有关系:
  12. // 如果DataIndex == -1,则表示在整个文件的范围。
  13. // 如果DataIndex >= 0,则表示在文件的某个分片的范围。
  14. GetRange() math2.Range
  15. GetStreamIndex() StreamIndex
  16. }
  17. const (
  18. // 未处理的完整文件流
  19. StreamIndexRaw = iota
  20. // EC编码的某一块的流
  21. StreamIndexEC
  22. // 分段编码的某一段的流
  23. StreamIndexSegment
  24. )
  25. type StreamIndex struct {
  26. Type int
  27. Index int
  28. }
  29. func RawStream() StreamIndex {
  30. return StreamIndex{
  31. Type: StreamIndexRaw,
  32. }
  33. }
  34. func ECStream(index int) StreamIndex {
  35. return StreamIndex{
  36. Type: StreamIndexEC,
  37. Index: index,
  38. }
  39. }
  40. func SegmentStream(index int) StreamIndex {
  41. return StreamIndex{
  42. Type: StreamIndexSegment,
  43. Index: index,
  44. }
  45. }
  46. func (s StreamIndex) IsRaw() bool {
  47. return s.Type == StreamIndexRaw
  48. }
  49. func (s StreamIndex) IsEC() bool {
  50. return s.Type == StreamIndexEC
  51. }
  52. func (s StreamIndex) IsSegment() bool {
  53. return s.Type == StreamIndexSegment
  54. }
  55. type FromTos []FromTo
  56. type FromTo struct {
  57. // 如果输入或者输出用到了EC编码的流,则需要提供EC参数。
  58. ECParam *clitypes.ECRedundancy
  59. // 同上
  60. SegmentParam *clitypes.SegmentRedundancy
  61. Froms []From
  62. Toes []To
  63. }
  64. func NewFromTo() FromTo {
  65. return FromTo{}
  66. }
  67. func (ft *FromTo) AddFrom(from From) *FromTo {
  68. ft.Froms = append(ft.Froms, from)
  69. return ft
  70. }
  71. func (ft *FromTo) AddTo(to To) *FromTo {
  72. ft.Toes = append(ft.Toes, to)
  73. return ft
  74. }
  75. type FromDriver struct {
  76. Handle *exec.DriverWriteStream
  77. StreamIndex StreamIndex
  78. }
  79. func NewFromDriver(strIdx StreamIndex) (*FromDriver, *exec.DriverWriteStream) {
  80. handle := &exec.DriverWriteStream{
  81. RangeHint: &math2.Range{},
  82. }
  83. return &FromDriver{
  84. Handle: handle,
  85. StreamIndex: strIdx,
  86. }, handle
  87. }
  88. func (f *FromDriver) GetStreamIndex() StreamIndex {
  89. return f.StreamIndex
  90. }
  91. type FromShardstore struct {
  92. FileHash clitypes.FileHash
  93. UserSpace clitypes.UserSpaceDetail
  94. StreamIndex StreamIndex
  95. }
  96. func NewFromShardstore(fileHash clitypes.FileHash, space clitypes.UserSpaceDetail, strIdx StreamIndex) *FromShardstore {
  97. return &FromShardstore{
  98. FileHash: fileHash,
  99. UserSpace: space,
  100. StreamIndex: strIdx,
  101. }
  102. }
  103. func (f *FromShardstore) GetStreamIndex() StreamIndex {
  104. return f.StreamIndex
  105. }
  106. type FromBaseStore struct {
  107. UserSpace clitypes.UserSpaceDetail
  108. Path string
  109. }
  110. func NewFromBaseStore(space clitypes.UserSpaceDetail, path string) *FromBaseStore {
  111. return &FromBaseStore{
  112. UserSpace: space,
  113. Path: path,
  114. }
  115. }
  116. func (f *FromBaseStore) GetStreamIndex() StreamIndex {
  117. return StreamIndex{
  118. Type: StreamIndexRaw,
  119. }
  120. }
  121. type ToDriver struct {
  122. Handle *exec.DriverReadStream
  123. StreamIndex StreamIndex
  124. Range math2.Range
  125. }
  126. func NewToDriver(strIdx StreamIndex) (*ToDriver, *exec.DriverReadStream) {
  127. str := exec.DriverReadStream{}
  128. return &ToDriver{
  129. Handle: &str,
  130. StreamIndex: strIdx,
  131. }, &str
  132. }
  133. func NewToDriverWithRange(strIdx StreamIndex, rng math2.Range) (*ToDriver, *exec.DriverReadStream) {
  134. str := exec.DriverReadStream{}
  135. return &ToDriver{
  136. Handle: &str,
  137. StreamIndex: strIdx,
  138. Range: rng,
  139. }, &str
  140. }
  141. func (t *ToDriver) GetStreamIndex() StreamIndex {
  142. return t.StreamIndex
  143. }
  144. func (t *ToDriver) GetRange() math2.Range {
  145. return t.Range
  146. }
  147. type ToShardStore struct {
  148. Space clitypes.UserSpaceDetail
  149. StreamIndex StreamIndex
  150. Range math2.Range
  151. FileHashStoreKey string
  152. }
  153. func NewToShardStore(space clitypes.UserSpaceDetail, strIdx StreamIndex, fileHashStoreKey string) *ToShardStore {
  154. return &ToShardStore{
  155. Space: space,
  156. StreamIndex: strIdx,
  157. FileHashStoreKey: fileHashStoreKey,
  158. }
  159. }
  160. func NewToShardStoreWithRange(space clitypes.UserSpaceDetail, streamIndex StreamIndex, fileHashStoreKey string, rng math2.Range) *ToShardStore {
  161. return &ToShardStore{
  162. Space: space,
  163. StreamIndex: streamIndex,
  164. FileHashStoreKey: fileHashStoreKey,
  165. Range: rng,
  166. }
  167. }
  168. func (t *ToShardStore) GetStreamIndex() StreamIndex {
  169. return t.StreamIndex
  170. }
  171. func (t *ToShardStore) GetRange() math2.Range {
  172. return t.Range
  173. }
  174. type ToBaseStore struct {
  175. Space clitypes.UserSpaceDetail
  176. ObjectPath string
  177. }
  178. func NewToBaseStore(space clitypes.UserSpaceDetail, objectPath string) *ToBaseStore {
  179. return &ToBaseStore{
  180. Space: space,
  181. ObjectPath: objectPath,
  182. }
  183. }
  184. func (t *ToBaseStore) GetStreamIndex() StreamIndex {
  185. return StreamIndex{
  186. Type: StreamIndexRaw,
  187. }
  188. }
  189. func (t *ToBaseStore) GetRange() math2.Range {
  190. return math2.Range{}
  191. }

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