@@ -1097,32 +1097,36 @@ export const serialize = (data, options = {}) => {
1097
1097
return ratio <= 0.85 ? t : s ;
1098
1098
} ;
1099
1099
1100
- export const deserialize = s => {
1101
- if ( s . startsWith ( MAGICLZ4PREFIX ) ) {
1102
- refCounter = 1 ;
1103
- readStr = s ;
1104
- readEnd = s . length ;
1105
- readPtr = MAGICLZ4PREFIX . length ;
1106
- const lz4 = _deserialize ( ) ;
1107
- readRefs . clear ( ) ;
1108
- readStr = '' ;
1109
- const lz4Util = new LZ4BlockJS ( ) ;
1110
- const uint8ArrayAfter = lz4Util . decode ( lz4 . data , 0 , lz4 . size ) ;
1111
- s = textCodec . decode ( new Uint8Array ( uint8ArrayAfter ) ) ;
1112
- }
1113
- if ( s . startsWith ( MAGICPREFIX ) === false ) { return ; }
1100
+ const deserializeById = ( blockid , s ) => {
1114
1101
refCounter = 1 ;
1115
1102
readStr = s ;
1116
1103
readEnd = s . length ;
1117
- readPtr = MAGICPREFIX . length ;
1104
+ readPtr = blockid . length ;
1118
1105
const data = _deserialize ( ) ;
1119
1106
readRefs . clear ( ) ;
1120
1107
readStr = '' ;
1121
- uint8Input = null ;
1122
1108
if ( readPtr === FAILMARK ) { return ; }
1123
1109
return data ;
1124
1110
} ;
1125
1111
1112
+ export const deserialize = s => {
1113
+ if ( s . startsWith ( MAGICLZ4PREFIX ) ) {
1114
+ const lz4 = deserializeById ( MAGICLZ4PREFIX , s ) ;
1115
+ if ( lz4 ) {
1116
+ const lz4Util = new LZ4BlockJS ( ) ;
1117
+ const uint8ArrayAfter = lz4Util . decode ( lz4 . data , 0 , lz4 . size ) ;
1118
+ if ( uint8ArrayAfter ) {
1119
+ s = textCodec . decode ( new Uint8Array ( uint8ArrayAfter ) ) ;
1120
+ }
1121
+ }
1122
+ }
1123
+ const data = s . startsWith ( MAGICPREFIX )
1124
+ ? deserializeById ( MAGICPREFIX , s )
1125
+ : undefined ;
1126
+ uint8Input = null ;
1127
+ return data ;
1128
+ } ;
1129
+
1126
1130
export const isSerialized = s =>
1127
1131
typeof s === 'string' &&
1128
1132
( s . startsWith ( MAGICLZ4PREFIX ) || s . startsWith ( MAGICPREFIX ) ) ;
0 commit comments