-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstorageKeys.ts
80 lines (68 loc) · 2.37 KB
/
storageKeys.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { strToBytes, U32 } from '@massalabs/massa-web3'
export const FILE_TAG: Uint8Array = strToBytes('\x01FILE')
export const FILE_LOCATION_TAG: Uint8Array = strToBytes('\x02LOCATION')
export const CHUNK_TAG: Uint8Array = strToBytes('\x03CHUNK')
export const CHUNK_NB_TAG: Uint8Array = strToBytes('\x04CHUNK_NB')
export const FILE_METADATA_TAG: Uint8Array = strToBytes('\x05FM')
export const GLOBAL_METADATA_TAG: Uint8Array = strToBytes('\x06GM')
export const DEWEB_VERSION_TAG: Uint8Array = strToBytes('\xFFDEWEB_VERSION')
export function globalMetadataKey(metadataKey: Uint8Array): Uint8Array {
const newKey = new Uint8Array(GLOBAL_METADATA_TAG.length + metadataKey.length)
var offset = 0
newKey.set(GLOBAL_METADATA_TAG, offset)
offset += GLOBAL_METADATA_TAG.length
newKey.set(metadataKey, offset)
return newKey
}
export function fileMetadataKey(
hashLocation: Uint8Array,
metadataKey: Uint8Array = new Uint8Array()
): Uint8Array {
const newKey = new Uint8Array(
FILE_METADATA_TAG.length + hashLocation.length + metadataKey.length
)
var offset = 0
newKey.set(FILE_METADATA_TAG, offset)
offset += FILE_METADATA_TAG.length
newKey.set(hashLocation, offset)
offset += hashLocation.length
newKey.set(metadataKey, offset)
return newKey
}
export function fileLocationKey(hashLocation: Uint8Array): Uint8Array {
const newKey = new Uint8Array(FILE_LOCATION_TAG.length + hashLocation.length)
var offset = 0
newKey.set(FILE_LOCATION_TAG, offset)
offset += FILE_LOCATION_TAG.length
newKey.set(hashLocation, offset)
return newKey
}
export function fileChunkCountKey(hashLocation: Uint8Array): Uint8Array {
const newKey = new Uint8Array(
FILE_TAG.length + CHUNK_NB_TAG.length + hashLocation.length
)
var offset = 0
newKey.set(FILE_TAG, offset)
offset += FILE_TAG.length
newKey.set(hashLocation, offset)
offset += hashLocation.length
newKey.set(CHUNK_NB_TAG, offset)
return newKey
}
export function fileChunkKey(
hashLocation: Uint8Array,
index: bigint
): Uint8Array {
const newKey = new Uint8Array(
FILE_TAG.length + hashLocation.length + CHUNK_TAG.length + U32.SIZE_BYTE
)
var offset = 0
newKey.set(FILE_TAG, offset)
offset += FILE_TAG.length
newKey.set(hashLocation, offset)
offset += hashLocation.length
newKey.set(CHUNK_TAG, offset)
offset += CHUNK_TAG.length
newKey.set(U32.toBytes(index), offset)
return newKey
}