11'use strict'
22
3- const { Buffer } = require ( 'buffer' )
43const protons = require ( 'protons' )
54const proto = protons ( require ( './dag.proto' ) )
65const DAGLink = require ( './dag-link/dagLink' )
@@ -30,7 +29,7 @@ const cid = (binaryBlob, userOptions) => {
3029 * Serialize internal representation into a binary PB block.
3130 *
3231 * @param {Object } node - Internal representation of a CBOR block
33- * @returns {Buffer } - The encoded binary representation
32+ * @returns {Uint8Array } - The encoded binary representation
3433 */
3534const serialize = ( node ) => {
3635 if ( DAGNode . isDAGNode ( node ) ) {
@@ -43,7 +42,7 @@ const serialize = (node) => {
4342/**
4443 * Deserialize PB block into the internal representation.
4544 *
46- * @param {Buffer } buffer - Binary representation of a PB block
45+ * @param {Uint8Array } buffer - Binary representation of a PB block
4746 * @returns {Object } - An object that conforms to the IPLD Data Model
4847 */
4948const deserialize = ( buffer ) => {
@@ -53,9 +52,9 @@ const deserialize = (buffer) => {
5352 return new DAGLink ( link . Name , link . Tsize , link . Hash )
5453 } )
5554
56- const data = pbn . Data == null ? Buffer . alloc ( 0 ) : pbn . Data
55+ const data = pbn . Data == null ? new Uint8Array ( 0 ) : pbn . Data
5756
58- return new DAGNode ( data , links , buffer . length )
57+ return new DAGNode ( data , links , buffer . byteLength )
5958}
6059
6160exports . serialize = serialize
0 commit comments