|
3 | 3 | const ModuleError = require('module-error') |
4 | 4 | const encodings = require('./lib/encodings') |
5 | 5 | const { Encoding } = require('./lib/encoding') |
6 | | -const { BufferFormat, ViewFormat, UTF8Format, NativeFormat } = require('./lib/formats') |
| 6 | +const { BufferFormat, ViewFormat, UTF8Format } = require('./lib/formats') |
7 | 7 |
|
8 | 8 | const kFormats = Symbol('formats') |
9 | 9 | const kEncodings = Symbol('encodings') |
@@ -57,7 +57,6 @@ class Transcoder { |
57 | 57 | return Array.from(types) |
58 | 58 | } |
59 | 59 |
|
60 | | - // TODO: document that we don't fallback to 'id' anymore if encoding is not found |
61 | 60 | /** |
62 | 61 | * @param {string|Encoding<any, any, any>|EncodingOptions<any, any, any>} encoding |
63 | 62 | * @returns {Encoding<any, T, any>} |
@@ -87,22 +86,18 @@ class Transcoder { |
87 | 86 | resolved = new BufferFormat(encoding) |
88 | 87 | } |
89 | 88 |
|
90 | | - const { type, idempotent, format } = resolved |
| 89 | + const { type, format } = resolved |
91 | 90 |
|
92 | | - if (this[kFormats].has(type)) { |
93 | | - // If idempotent, run data through it to normalize |
94 | | - if (!idempotent) resolved = new NativeFormat(type) |
95 | | - } else if (!this[kFormats].has(format)) { |
| 91 | + if (!this[kFormats].has(format)) { |
96 | 92 | if (this[kFormats].has('view')) { |
97 | 93 | resolved = resolved.transcode('view') |
98 | 94 | } else if (this[kFormats].has('buffer')) { |
99 | 95 | resolved = resolved.transcode('buffer') |
100 | 96 | } else { |
101 | 97 | // TODO: improve error message (see tests, it's inconsistent) |
102 | | - throw new ModuleError( |
103 | | - `Encoding '${type}' is not supported`, |
104 | | - { code: 'LEVEL_ENCODING_NOT_SUPPORTED' } |
105 | | - ) |
| 98 | + throw new ModuleError(`Encoding '${type}' is not supported`, { |
| 99 | + code: 'LEVEL_ENCODING_NOT_SUPPORTED' |
| 100 | + }) |
106 | 101 | } |
107 | 102 | } |
108 | 103 |
|
|
0 commit comments