using System;
using System.IO;
namespace Discord
{
///
/// An image that will be uploaded to Discord.
///
public struct Image : IDisposable
{
private bool _isDisposed;
///
/// Gets the stream to be uploaded to Discord.
///
#pragma warning disable IDISP008
public Stream Stream { get; }
#pragma warning restore IDISP008
///
/// Create the image with a .
///
///
/// The to create the image with. Note that this must be some type of stream
/// with the contents of a file in it.
///
public Image(Stream stream)
{
_isDisposed = false;
Stream = stream;
}
///
/// Create the image from a file path.
///
///
/// This file path is NOT validated and is passed directly into a
/// .
///
/// The path to the file.
///
/// is a zero-length string, contains only white space, or contains one or more invalid
/// characters as defined by .
///
/// is null.
///
/// The specified path, file name, or both exceed the system-defined maximum length. For example, on
/// Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260
/// characters.
///
/// is in an invalid format.
///
/// The specified is invalid, (for example, it is on an unmapped drive).
///
///
/// specified a directory.-or- The caller does not have the required permission.
///
/// The file specified in was not found.
///
/// An I/O error occurred while opening the file.
public Image(string path)
{
_isDisposed = false;
Stream = File.OpenRead(path);
}
///
public void Dispose()
{
if (!_isDisposed)
{
#pragma warning disable IDISP007
Stream?.Dispose();
#pragma warning restore IDISP007
_isDisposed = true;
}
}
}
}