Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

string_decoder

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string_decoder

The string_decoder module from Node core

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
115M
decreased by-4.97%
Maintainers
5
Weekly downloads
 
Created

What is string_decoder?

The string_decoder npm package is used to decode buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters. It is particularly useful when dealing with streams of data that may contain such characters.

What are string_decoder's main functionalities?

Decoding Buffers to Strings

This feature allows for the conversion of buffer objects into strings, ensuring that multi-byte characters are not improperly split at the end of a buffer.

{"const { StringDecoder } = require('string_decoder'); const decoder = new StringDecoder('utf8'); const buffer = Buffer.from([0xE2, 0x82, 0xAC]); console.log(decoder.write(buffer)); // Outputs: '€'"}

Handling Incomplete Multi-byte Characters

This feature is useful when buffers are received in chunks and multi-byte characters are spread across multiple chunks. The StringDecoder ensures that these characters are not converted until the complete character is received.

{"const { StringDecoder } = require('string_decoder'); const decoder = new StringDecoder('utf8'); const buffers = [Buffer.from([0xE2]), Buffer.from([0x82]), Buffer.from([0xAC])]; let result = ''; buffers.forEach((buffer) => { result += decoder.write(buffer); }); result += decoder.end(); console.log(result); // Outputs: '€'"}

Other packages similar to string_decoder

Keywords

FAQs

Package last updated on 07 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc