We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 77ed12f commit 314c6b3Copy full SHA for 314c6b3
1 file changed
lib/string_decoder.js
@@ -19,8 +19,15 @@
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
+function assertEncoding(encoding) {
23
+ if (encoding && !Buffer.isEncoding(encoding)) {
24
+ throw new Error('Unknown encoding: ' + encoding);
25
+ }
26
+}
27
+
28
var StringDecoder = exports.StringDecoder = function(encoding) {
29
this.encoding = (encoding || 'utf8').toLowerCase().replace(/[-_]/, '');
30
+ assertEncoding(encoding);
31
switch (this.encoding) {
32
case 'utf8':
33
// CESU-8 represents each of Surrogate Pair by 3-bytes
0 commit comments