{"library":"msgpack-lite","title":"msgpack-lite","description":"msgpack-lite is a pure JavaScript implementation of the MessagePack serialization format, providing fast encoding and decoding capabilities for both Node.js and web browsers. As of version 0.1.26, it offers synchronous `encode` and `decode` functions, along with streaming interfaces via `createEncodeStream` and `createDecodeStream`. It differentiated itself by claiming performance superior to some C++ MessagePack libraries for Node.js v4, without requiring native C++ compilation (node-gyp). The library supports various input types for decoding, including Node.js `Buffer`, standard JavaScript `Array`, and `Uint8Array`. It was tested on older Node.js versions (v0.10 through v6) and a wide range of browsers, including IE8. The last release was over 8 years ago, indicating it is no longer actively maintained.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install msgpack-lite"],"cli":null},"imports":["const msgpack = require('msgpack-lite');","const { encode, decode } = require('msgpack-lite'); // Not recommended for direct destructuring\n// Or, preferably:\nconst msgpack = require('msgpack-lite');\nconst encoded = msgpack.encode(data);","const msgpack = require('msgpack-lite');\nconst encodeStream = msgpack.createEncodeStream();"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const fs = require('fs');\nconst msgpack = require('msgpack-lite');\n\n// Example 1: Basic synchronous encoding and decoding\nconst dataToSend = { id: 1, message: 'Hello, MessagePack!', timestamp: Date.now() };\nconst buffer = msgpack.encode(dataToSend);\nconsole.log('Encoded buffer:', buffer.toString('hex'));\nconst decodedData = msgpack.decode(buffer);\nconsole.log('Decoded data:', decodedData);\n\n// Example 2: Streaming encoding and decoding\n// Prepare a dummy file path for demonstration\nconst filePath = 'temp_data.msp';\n\nconst writeStream = fs.createWriteStream(filePath);\nconst encodeStream = msgpack.createEncodeStream();\n\nencodeStream.pipe(writeStream);\n\nencodeStream.write({ event: 'start', time: Date.now() });\nencodeStream.write({ user: 'Alice', action: 'login' });\nencodeStream.write({ user: 'Bob', action: 'logout' });\n\n// Ensure stream closes after all data is written\nencodeStream.end(() => {\n  console.log(`\nSuccessfully wrote MessagePack data to ${filePath}`);\n\n  // Now read from the stream\n  const readStream = fs.createReadStream(filePath);\n  const decodeStream = msgpack.createDecodeStream();\n\n  console.log('Decoding stream data:');\n  readStream.pipe(decodeStream).on('data', (obj) => {\n    console.log('Stream decoded object:', obj);\n  });\n\n  decodeStream.on('end', () => {\n    console.log('Finished decoding stream.');\n    fs.unlinkSync(filePath); // Clean up the dummy file\n  });\n\n  decodeStream.on('error', (err) => {\n    console.error('Error decoding stream:', err);\n    fs.unlinkSync(filePath); // Clean up on error\n  });\n});\n\nwriteStream.on('error', (err) => {\n  console.error('Error writing to stream:', err);\n  fs.unlinkSync(filePath); // Clean up on error\n});\n","lang":"javascript","description":"This quickstart demonstrates both synchronous MessagePack encoding/decoding and the use of streaming APIs to write and read multiple MessagePack objects to/from a file, including proper error handling and cleanup for the file system operations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}