You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After enabling serialization for FileBox, we can transfer the FileBox on the wire.
Talk is cheap, show me the code
constfileBox=FileBox.fromQRCode('https://github.com')constjsonText=JSON.stringify(fileBox)// the above code equals to the following line of code:// const jsonText = fileBox.toJSON()// we will get the serialized data for this FileBox:console.log(jsonText)// restore our fleBox:constnewFileBox=FileBox.fromJSON(jsonText)
Limitation
Because we want to enable the JSON.stringify(fileBox), which will call fileBox.toJSON(), so the toJSON() can not be async, which means we can only support limited FileBoxType(s):
FileBoxType.Base64
FileBoxType.Url
FileBoxType.QRCode
For other types like FileBoxType.Flie, FileBoxType.Buffer, FileBoxType.Stream, etc, we need to transform them to FileBoxType.Base64 before we call toJSON:
constfileBoxBefore=FileBox.fromFile('./test.txt')constbase64=awaitfileBoxBefore.toBase64()constfileBoxAfter=FleBox.fromBase64(base64,'test.txt')// fileBoxAfter will be serializableconsole.log(JSON.stringify(fileBoxAfter))
The text was updated successfully, but these errors were encountered:
After enabling serialization for FileBox, we can transfer the FileBox on the wire.
Talk is cheap, show me the code
Limitation
Because we want to enable the
JSON.stringify(fileBox)
, which will callfileBox.toJSON()
, so thetoJSON()
can not beasync
, which means we can only support limited FileBoxType(s):For other types like
FileBoxType.Flie
,FileBoxType.Buffer
,FileBoxType.Stream
, etc, we need to transform them toFileBoxType.Base64
before we calltoJSON
:The text was updated successfully, but these errors were encountered: