import { injectable } from 'inversify' ; import { ContentDecoderInterface } from './ContentDecoderInterface' ; @ injectable ( ) export class ContentDecoder implements ContentDecoderInterface { decode ( content ) { try { const contentBuffer = Buffer . from ( content . substring ( 3 ) , 'base64' ) ; const decodedContent = contentBuffer . toString ( ) ; return JSON . parse ( decodedContent ) ; } catch ( error ) { return { } ; } } encode ( content ) { const stringifiedContent = JSON . stringify ( content ) ; return `000${ Buffer . from ( stringifiedContent ) . toString ( 'base64' ) }` ; } }