mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Backporting Attachments (#1817)
This commit is contained in:
@@ -234,6 +234,33 @@ class ClientDataResolver {
|
||||
return Promise.reject(new TypeError('The resource must be a string or Buffer.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @external Stream
|
||||
* @see {@link https://nodejs.org/api/stream.html}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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('The resource must be a string, Buffer or a valid file stream.');
|
||||
}
|
||||
}) :
|
||||
Promise.reject(new TypeError('The resource must be a string, Buffer or a valid file stream.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an emoji identifier. This can be:
|
||||
* * The unicode representation of an emoji
|
||||
|
||||
Reference in New Issue
Block a user