How to use the deserialize function from bson

Find comprehensive JavaScript bson.deserialize code examples handpicked from public code repositorys.

155
156
157
158
159
160
161
162
163
164
    let docSizeBuf = Buffer.alloc(4)
    fs.readSync(blocks.fd,docSizeBuf,{offset: 0, position: docPosition, length: 4})
    let docSize = docSizeBuf.readInt32LE(0)
    let docBuf = Buffer.alloc(docSize)
    fs.readSync(blocks.fd,docBuf,{offset: 0, position: docPosition, length: docSize})
    return BSON.deserialize(docBuf)
},
readRange: (start,end) => {
    if (!blocks.isOpen)
        throw new Error(blocks.notOpenError)
fork icon64
star icon93
watch icon0

1
2
3
4
5
6
7
8
9
10
const BSON = require('bson')

const buffer = fs.readFileSync(process.argv[2])

const deserialize = (buffer) => {
  const object = BSON.deserialize(buffer)
  const keys = Object.keys(object)

  if (keys.every((key) => {
    return !isNaN(parseInt(key, 10))
fork icon1
star icon18
watch icon4

+ 3 other calls in file

32
33
34
35
36
37
38
39
40
41

this.socket = new TcpClient(port, host, define.some_config.SocketBufferMaxLen, true, this.connectCb.bind(this));

this.socket.on("data", (buf: Buffer) => {
    // console.log("what the fuck222222222222222222");
    let data = BSON.deserialize(buf);
    let reqId = data.reqId;
    let req = this.reqs[reqId];
    if (!req) {
        return;
fork icon3
star icon8
watch icon1

+ 3 other calls in file

4
5
6
7
8
9
10
11
12
13
class Database {
  constructor() {
    this.write = txt => fs.writeFileSync(this.file, txt, 'utf8', () => {});
    this.file = "inflames.bson";
    try {
        this.database = BSON.deserialize(fs.readFileSync(this.file));
    } catch (e) {
        this.write("")
        this.database = {};
    }
fork icon1
star icon7
watch icon1

+ 13 other calls in file

63
64
65
66
67
68
69
70
71
72
// Serialize a document
const data = BSON.serialize(doc);
console.log('data:', data);

// Deserialize the resulting Buffer
const doc_2 = BSON.deserialize(data);
console.log('doc_2:', doc_2);
```

## Installation
fork icon1
star icon1
watch icon3

+ 7 other calls in file

193
194
195
196
197
198
199
200
201
202
        });    
    }, 5000);
});

socket.on('message', function(message, remote) {
    var obj = bson.deserialize(message);
    //console.log('new message ------------');
    //console.log(obj);
    if(heartbeatReceived) {
        heartbeatReceived(obj);
fork icon0
star icon5
watch icon2

1
2
3
4
5
6
7
8
9
10
11
12
const bson = require('bson');
const fs = require('fs');
var packetQueue = [];


function BSONDecode(buffer) {
    return bson.deserialize(buffer.slice(4));
}


function BSONEncode(json) {
    const data = bson.serialize(json);
fork icon0
star icon4
watch icon0

158
159
160
161
162
163
164
165
166
167
  e: /[A-Za-z0-9]*/,
  f: new BSON.BSONRegExp('[A-Za-z0-9]*'),
  g: undefined
};

const expected = BSON.deserialize(BSON.serialize(data, bsonOptions), bsonOptions);

const coll = this.encryptedClient.db(dataDbName).collection(dataCollName);
return Promise.resolve()
  .then(() => coll.insertOne(data, bsonOptions))
fork icon0
star icon0
watch icon0

+ 3 other calls in file

152
153
154
155
156
157
158
159
160
161

let rawdoc = Buffer.concat(this._buffers, this._doclen);
let obj;

try {
  obj = BSON.deserialize(rawdoc);
} catch (err) {
  // discard buffer
  this._reset();
  cb(err);
fork icon0
star icon0
watch icon0

151
152
153
154
155
156
157
158
159
160
161
//  * Deserealize data from BSON
//  * @param {*} buffer buffer to deserialize
//  * @returns {Object} deserialized object
//  */
// const BJSONDeserialize = (buffer) => {
//   return deserialize(buffer);
// }


/**
 * load json file return object 
fork icon0
star icon0
watch icon0

316
317
318
319
320
321
322
323
324
325

    const data = await database.then(db => db.findOne({ guildId: context.guildId, storageId }))
        .catch(() => { throw context.error("Couldn't get data from database"); });
    if (!data) return new c.NullLiteral;

    const json = BSON.deserialize(data.data.buffer);

    const value = c.convert(json[key]);
    return value;
}),
fork icon0
star icon0
watch icon0

+ 5 other calls in file