using System;
using System.Runtime.InteropServices;
namespace NetVips;
///
/// Manage a .
///
internal class VipsBlob : SafeHandle
{
///
/// Initializes a new instance of the class
/// with the specified pointer to wrap around.
///
/// The pointer to wrap around.
internal VipsBlob(nint pointer) : base(IntPtr.Zero, true)
{
// record the pointer we were given to manage
SetHandle(pointer);
}
///
/// Get the data from a .
///
/// Return number of bytes of data.
/// A containing the data.
internal nint GetData(out nuint length)
{
return Internal.VipsBlob.Get(this, out length);
}
///
/// Decreases the reference count of the blob.
/// When its reference count drops to 0, the blob is finalized (i.e. its memory is freed).
///
/// if the handle is released successfully; otherwise,
/// in the event of a catastrophic failure, .
protected override bool ReleaseHandle()
{
if (!IsInvalid)
{
// Free the VipsArea
Internal.VipsArea.Unref(handle);
}
return true;
}
///
/// Gets a value indicating whether the handle is invalid.
///
/// if the handle is not valid; otherwise, .
public override bool IsInvalid => handle == IntPtr.Zero;
///
/// Get the number of bytes of data.
///
internal ulong Length => Marshal.PtrToStructure(handle).Length;
///
/// Get the reference count of the blob. Handy for debugging.
///
internal int RefCount => Marshal.PtrToStructure(handle).Count;
}