Struct lofty::Picture

source ·
pub struct Picture { /* private fields */ }
Expand description

Represents a picture.

Implementations§

source§

impl Picture

source

pub fn from_reader<R>(reader: &mut R) -> Result<Self>
where R: Read,

Create a Picture from a reader

NOTES:

  • This is for reading picture data only, from a File for example.
  • pic_type will always be PictureType::Other, be sure to change it accordingly if writing.
§Errors
  • reader contains less than 8 bytes
  • reader does not contain a supported format. See MimeType for valid formats
source

pub fn new_unchecked( pic_type: PictureType, mime_type: Option<MimeType>, description: Option<String>, data: Vec<u8> ) -> Self

Create a new Picture

NOTE: This will not verify data’s signature. This should only be used if all data has been verified beforehand.

source

pub fn pic_type(&self) -> PictureType

Returns the PictureType

source

pub fn set_pic_type(&mut self, pic_type: PictureType)

Sets the PictureType

source

pub fn mime_type(&self) -> Option<&MimeType>

Returns the MimeType

The mime_type is determined from the data, and is immutable.

source

pub fn description(&self) -> Option<&str>

Returns the description

source

pub fn set_description(&mut self, description: Option<String>)

Sets the description

source

pub fn data(&self) -> &[u8]

Returns the Picture data as borrowed bytes.

source

pub fn into_data(self) -> Vec<u8>

Consumes a Picture, returning the data as Vec without clones or allocation.

source

pub fn as_flac_bytes( &self, picture_information: PictureInformation, encode: bool ) -> Vec<u8>

Convert a Picture to a base64 encoded FLAC METADATA_BLOCK_PICTURE String

Use encode to convert the picture to a base64 encoded String (RFC 4648 §4)

NOTES:

  • This does not include a key (Vorbis comments) or METADATA_BLOCK_HEADER (FLAC blocks)
  • FLAC blocks have different size requirements than OGG Vorbis/Opus, size is not checked here
  • When writing to Vorbis comments, the data must be base64 encoded
source

pub fn from_flac_bytes( bytes: &[u8], encoded: bool, parse_mode: ParsingMode ) -> Result<(Self, PictureInformation)>

Get a Picture from FLAC METADATA_BLOCK_PICTURE bytes:

NOTE: This takes both the base64 encoded string from Vorbis comments, and the raw data from a FLAC block, specified with encoded.

§Errors

This function will return NotAPicture if at any point it’s unable to parse the data

source

pub fn as_ape_bytes(&self) -> Vec<u8>

Convert a Picture to an APE Cover Art byte vec:

NOTE: This is only the picture data and description, a key and terminating null byte will not be prepended. To map a PictureType to an APE key see PictureType::as_ape_key

source

pub fn from_ape_bytes(key: &str, bytes: &[u8]) -> Result<Self>

Get a Picture from an APEv2 binary item:

NOTE: This function expects bytes to contain only the APE item data

§Errors

This function will return NotAPicture if at any point it’s unable to parse the data

Trait Implementations§

source§

impl Clone for Picture

source§

fn clone(&self) -> Picture

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Picture

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Picture

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Picture

source§

fn eq(&self, other: &Picture) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Picture

source§

impl StructuralEq for Picture

source§

impl StructuralPartialEq for Picture

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.