import { Buffer } from './internal/buffer' ; import * as errors from './internal/errors' ; export type TDataOut = string | Buffer ; export type TEncodingExtended = BufferEncoding | 'buffer' ; export const ENCODING_UTF8 = 'utf8' ; export function assertEncoding ( encoding ) { if ( encoding && ! Buffer . isEncoding ( encoding ) ) throw new errors . TypeError ( 'ERR_INVALID_OPT_VALUE_ENCODING' , encoding ) ; } export function strToEncoding ( str , encoding ? ) { if ( ! encoding || encoding === ENCODING_UTF8 ) return str ; if ( encoding === 'buffer' ) return new Buffer ( str ) ; return new Buffer ( str ) . toString ( encoding ) ; }