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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package ioswitchlrc
  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 FromDriver struct {
  17. Handle *exec.DriverWriteStream
  18. DataIndex int
  19. }
  20. func NewFromDriver(dataIndex int) (*FromDriver, *exec.DriverWriteStream) {
  21. handle := &exec.DriverWriteStream{
  22. RangeHint: &exec.Range{},
  23. }
  24. return &FromDriver{
  25. Handle: handle,
  26. DataIndex: dataIndex,
  27. }, handle
  28. }
  29. func (f *FromDriver) GetDataIndex() int {
  30. return f.DataIndex
  31. }
  32. type FromNode struct {
  33. FileHash cdssdk.FileHash
  34. Hub cdssdk.Hub
  35. Storage cdssdk.Storage
  36. DataIndex int
  37. }
  38. func NewFromStorage(fileHash cdssdk.FileHash, hub cdssdk.Hub, storage cdssdk.Storage, dataIndex int) *FromNode {
  39. return &FromNode{
  40. FileHash: fileHash,
  41. Hub: hub,
  42. DataIndex: dataIndex,
  43. }
  44. }
  45. func (f *FromNode) GetDataIndex() int {
  46. return f.DataIndex
  47. }
  48. type ToDriver struct {
  49. Handle *exec.DriverReadStream
  50. DataIndex int
  51. Range exec.Range
  52. }
  53. func NewToDriver(dataIndex int) (*ToDriver, *exec.DriverReadStream) {
  54. str := exec.DriverReadStream{}
  55. return &ToDriver{
  56. Handle: &str,
  57. DataIndex: dataIndex,
  58. }, &str
  59. }
  60. func NewToDriverWithRange(dataIndex int, rng exec.Range) (*ToDriver, *exec.DriverReadStream) {
  61. str := exec.DriverReadStream{}
  62. return &ToDriver{
  63. Handle: &str,
  64. DataIndex: dataIndex,
  65. Range: rng,
  66. }, &str
  67. }
  68. func (t *ToDriver) GetDataIndex() int {
  69. return t.DataIndex
  70. }
  71. func (t *ToDriver) GetRange() exec.Range {
  72. return t.Range
  73. }
  74. type ToNode struct {
  75. Hub cdssdk.Hub
  76. Storage cdssdk.Storage
  77. DataIndex int
  78. Range exec.Range
  79. FileHashStoreKey string
  80. }
  81. func NewToStorage(hub cdssdk.Hub, stg cdssdk.Storage, dataIndex int, fileHashStoreKey string) *ToNode {
  82. return &ToNode{
  83. Hub: hub,
  84. Storage: stg,
  85. DataIndex: dataIndex,
  86. FileHashStoreKey: fileHashStoreKey,
  87. }
  88. }
  89. func NewToStorageWithRange(hub cdssdk.Hub, stg cdssdk.Storage, dataIndex int, fileHashStoreKey string, rng exec.Range) *ToNode {
  90. return &ToNode{
  91. Hub: hub,
  92. Storage: stg,
  93. DataIndex: dataIndex,
  94. FileHashStoreKey: fileHashStoreKey,
  95. Range: rng,
  96. }
  97. }
  98. func (t *ToNode) GetDataIndex() int {
  99. return t.DataIndex
  100. }
  101. func (t *ToNode) GetRange() exec.Range {
  102. return t.Range
  103. }
  104. // type ToStorage struct {
  105. // Storage cdssdk.Storage
  106. // DataIndex int
  107. // }
  108. // func NewToStorage(storage cdssdk.Storage, dataIndex int) *ToStorage {
  109. // return &ToStorage{
  110. // Storage: storage,
  111. // DataIndex: dataIndex,
  112. // }
  113. // }
  114. // func (t *ToStorage) GetDataIndex() int {
  115. // return t.DataIndex
  116. // }

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