const ky = require('ky-universal');

module.exports = class Image {
    
    constructor(info) {
        Object.assign(this, info)
    }

    /**
     * getBuffer function
     * @returns {Promise<Buffer>}
     */

    getBuffer() {
        
        return new Promise(async (resolve, reject) => {
            
            let self = this;

            setImmediate(async () => {
                
                try {
                    
                    let res = await ky.get(self.media);

                    resolve(await res.buffer());

                } catch(e) {
                    return reject(new Error(e.toString()))
                } 

            })
        })

    }

}