Add Attachment structure (#1731)

* Add Attachment structure

* Fix linter issues + @private

* Fixed array sends, also added embed sends

* fixed proving path to attachment

* fixed incorrect name assumption from path

* linting fix

* ;)

* im really good at this

* changes as requested by gus

and computer from #1459

* am a dum

* update webhook#send

* readonly addition to getters

* i... uh... oops

* farming deez commits

* fix webhook split

* removed some ugly

* removed .every checks
This commit is contained in:
Isabella
2017-08-06 17:09:47 -05:00
committed by Schuyler Cebulskie
parent 317a352337
commit 62fc9fce6d
7 changed files with 199 additions and 22 deletions

View File

@@ -215,6 +215,28 @@ class ClientDataResolver {
return Promise.reject(new TypeError('REQ_RESOURCE_TYPE'));
}
/**
* Converts a Stream to a Buffer.
* @param {Stream} resource The stream to convert
* @returns {Promise<Buffer>}
*/
resolveFile(resource) {
return resource ? this.resolveBuffer(resource)
.catch(() => {
if (resource.pipe && typeof resource.pipe === 'function') {
return new Promise((resolve, reject) => {
const buffers = [];
resource.once('error', reject);
resource.on('data', data => buffers.push(data));
resource.once('end', () => resolve(Buffer.concat(buffers)));
});
} else {
throw new TypeError('REQ_RESOURCE_TYPE');
}
}) :
Promise.reject(new TypeError('REQ_RESOURCE_TYPE'));
}
/**
* Data that can be resolved to give an emoji identifier. This can be:
* * The unicode representation of an emoji