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

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

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