github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/storage-block.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package protocol 4 5 // StorageBlockVolatile or StorageMemory is the interface that show how an app access to volatile storage devices. 6 // Usually dev must not use this interface due to it can damage any data written by objects, files, records, k/v interfaces 7 type StorageBlockVolatile interface { 8 // return volume capacity 9 Cap() int 10 // Extended length may vary of requested cap, Due to Extend() is base on storage device block size not bytes, 11 // e.g. on SSDs block sizes are 256*page-size like 256*4(page-size)=1024(B)=1(MB) 12 Extend(cap int) (extended int, err Error) 13 14 // Change the return data not flush to any non-volatile storages. Use Write() to change data. 15 Read(offset, data []byte) (err Error) 16 // Write at more than block capacity cause block extend. extend capacity isn't equal to write length. 17 Write(offset, data []byte) (err Error) 18 Erase(offset, limit int) (err Error) 19 20 Copy(desOffset, srcOffset int, limit int) (err Error) 21 Move(desOffset, srcOffset int, limit int) (err Error) 22 23 Search(data []byte, offset int) (loc int, err Error) 24 } 25 26 // StorageBlock is the interface that show how an app access to storage devices. 27 // Usually dev must not use this interface due to it can damage any data written by objects, files, records or k/v interfaces 28 type StorageBlock interface { 29 StorageBlockVolatile 30 31 // Flush force the storage device to write any changes to data (store in cache) before call Flush. 32 Flush() (err Error) 33 }