Skip to content

Latest commit

 

History

History
934 lines (526 loc) · 20.7 KB

MpegAudioFile.md

File metadata and controls

934 lines (526 loc) · 20.7 KB

node-taglib-sharp / Exports / MpegAudioFile

Class: MpegAudioFile

This class extends SandwichFile to provide tagging and properties support for MPEG-1, MPEG-2, and MPEG-2.5 non-containerized audio files.

Hierarchy

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new MpegAudioFile(file, propertiesStyle)

Parameters

Name Type
file string | IFileAbstraction
propertiesStyle ReadStyle

Overrides

SandwichFile.constructor

Accessors

corruptionReasons

get corruptionReasons(): string[]

Reasons for which this file is marked as corrupt.

Returns

string[]

Inherited from

SandwichFile.corruptionReasons


endTag

Protected get endTag(): EndTag

Gets the collection of tags appearing at the end of the file.

Returns

EndTag

Inherited from

SandwichFile.endTag


fileAbstraction

get fileAbstraction(): IFileAbstraction

Gets the IFileAbstraction representing the file.

Returns

IFileAbstraction

Inherited from

SandwichFile.fileAbstraction


hasTags

get hasTags(): boolean

Shortcut property to determine if a file has tags in memory. NOTE: Just because tag !== undefined does not mean there are tags in memory.

Returns

boolean

Inherited from

SandwichFile.hasTags


isPossiblyCorrupt

get isPossiblyCorrupt(): boolean

Indicates whether this file may be corrupt. Files with unknown corruptions should not be written.

Returns

boolean

Inherited from

SandwichFile.isPossiblyCorrupt


isWritable

get isWritable(): boolean

Indicates whether tags can be written back to the current file.

Returns

boolean

Inherited from

SandwichFile.isWritable


length

get length(): number

Gets the length of the file represented by the current instance. Value will be 0 if the file is not open for reading;

Returns

number

Inherited from

SandwichFile.length


mediaEndPosition

get mediaEndPosition(): number

Gets the position at which the media content of this file ends.

Returns

number

Inherited from

SandwichFile.mediaEndPosition


mediaStartPosition

get mediaStartPosition(): number

Gets the position at which the media content of this file starts.

Returns

number

Inherited from

SandwichFile.mediaStartPosition


mimeType

get mimeType(): string

Gets the MimeType of the file as determined during creation of the instance.

Returns

string

Inherited from

SandwichFile.mimeType


mode

get mode(): FileAccessMode

Gets the file access mode in use by the current instance.

Returns

FileAccessMode

Inherited from

SandwichFile.mode

set mode(val): void

Sets the file access mode in use by the current instance. Changing the value will cause the stream currently in use to be closed, except when a change is made from Write to Read which has no effect.

Parameters

Name Type Description
val FileAccessMode File access mode to change to

Returns

void

Inherited from

SandwichFile.mode


name

get name(): string

Gets the name of the file as stored in its file abstraction.

Returns

string

Inherited from

SandwichFile.name


position

get position(): number

Gets the seek position in the internal stream used by the current instance. Value will be 0 if the file is not open for reading

Returns

number

Inherited from

SandwichFile.position


properties

get properties(): Properties

Gets the media properties of the file represented by the current instance.

Returns

Properties

Inherited from

SandwichFile.properties


startTag

Protected get startTag(): StartTag

Gets the collection of tags appearing at the start of the file.

Returns

StartTag

Inherited from

SandwichFile.startTag


tag

get tag(): SandwichTag

Gets an abstract representation of all tags stored in the current instance.

Returns

SandwichTag

Inherited from

SandwichFile.tag


tagTypes

get tagTypes(): TagTypes

Gets the tag types contained in the current instance.

Returns

TagTypes

Inherited from

SandwichFile.tagTypes


tagTypesOnDisk

get tagTypesOnDisk(): TagTypes

Gets the tag types contained in the physical file represented by the current instance.

Returns

TagTypes

Inherited from

SandwichFile.tagTypesOnDisk

set tagTypesOnDisk(value): void

Sets the tag types contained in the physical file represented by the current instance.

Parameters

Name Type
value TagTypes

Returns

void

Inherited from

SandwichFile.tagTypesOnDisk


bufferSize

Static get bufferSize(): number

Gets the buffer size to use when reading large blocks of data

Returns

number

Inherited from

SandwichFile.bufferSize

Methods

dispose

dispose(): void

Dispose the current instance. Equivalent to setting the mode to closed.

Returns

void

Inherited from

SandwichFile.dispose


find

find(pattern, startPosition?, before?): number

Searches forward through a file for a specified pattern, starting at a specified offset.

Throws

Error Thrown if pattern is not provided or startPosition is not a positive, safe integer.

Parameters

Name Type Default value Description
pattern ByteVector undefined Pattern to search for in the current instance. Must be smaller than the
startPosition number 0 Seek position to start searching. Must be positive, safe integer.
before? ByteVector undefined Optional pattern that the searched for pattern must appear before. If this pattern is found first, -1 is returned.

Returns

number

Index at which the value was found. If not found, -1 is returned.

Inherited from

SandwichFile.find


getTag

getTag(type, create): Tag

Gets a tag of the specified type from the current instance, optionally creating a new tag if possible.

Parameters

Name Type Description
type TagTypes Type of tag to read.
create boolean Whether or not to try and create the tag if one is not found. true does not guarantee the tag will be created. For example, trying to create an ID3v2 tag on an OGG Vorbis file will always fail.

Returns

Tag

Inherited from

SandwichFile.getTag


insert

insert(data, start, replace?): void

Inserts a specified block of data into the file represented by the current instance, at a specified location, replacing a specified number of bytes.

Throws

Error Thrown when: 1) data is falsey, 2) start is not a safe, positive number, or 3) replace is not a safe, positive number

Parameters

Name Type Default value Description
data ByteVector undefined Data to insert into the file.
start number undefined Index into the file at which to insert the data. Must be safe positive integer.
replace number 0 Number of bytes to replace. Typically, this is the original size of the data block so that a new block will replace the old one.

Returns

void

Inherited from

SandwichFile.insert


markAsCorrupt

markAsCorrupt(reason): void

Mark the current instance as corrupt. NOTE: Not intended to be used outside of this library.

Parameters

Name Type Description
reason string Reason why this file is considered to be corrupt

Returns

void

Inherited from

SandwichFile.markAsCorrupt


preSave

Protected preSave(): void

Prepares to save the file. This must be called at the beginning of every File.save() method.

Returns

void

Inherited from

SandwichFile.preSave


rFind

rFind(pattern, startPosition?): number

Searches backwards through a file for a specified pattern, starting at a specified offset.

Throws

Error Thrown if pattern was not provided or if startPosition is not a safe, positive integer.

Parameters

Name Type Default value Description
pattern ByteVector undefined Pattern to search for in the current instance. Must be shorter than the bufferSize
startPosition number 0 Number of bytes from end of the file to begin searching.

Returns

number

Index at which the value wa found. If not found, -1 is returned.

Inherited from

SandwichFile.rFind


readBlock

readBlock(length): ByteVector

Reads a specified number of bytes at the current seek position from the current position. This method reads the block of data at the current seek position. To change the seek position, use seek.

Throws

Error Thrown when length is not a positive, safe integer.

Parameters

Name Type Description
length number Number of bytes to read.

Returns

ByteVector

Object containing the data read from the current instance.

Inherited from

SandwichFile.readBlock


readProperties

Protected readProperties(readStyle): Properties

Reads the properties of the file.

Parameters

Name Type Description
readStyle ReadStyle Indicates what degree of accuracy the file properties are read, if at all.

Returns

Properties

Overrides

SandwichFile.readProperties


removeBlock

removeBlock(start, length): void

Removes a specified block of data from the file represented by the current instance.

Throws

Error thrown if 1) start is not a safe, positive integer or 2) length must be a safe integer.

Parameters

Name Type Description
start number Index into the file at which to remove data. Must be safe, positive integer.
length number Number of bytes to remove. Must be a safe integer.

Returns

void

Inherited from

SandwichFile.removeBlock


removeTags

removeTags(types): void

Removes a set of tag types from the current instance. In order to remove all tags from a file, pass AllTags as types

Parameters

Name Type Description
types TagTypes Bitwise combined TagTypes value containing the tag types to be removed from the file

Returns

void

Inherited from

SandwichFile.removeTags


save

save(): void

Saves the changes made in the current instance to the file it represents.

Returns

void

Inherited from

SandwichFile.save


seek

seek(offset, origin?): void

Moves the read/write pointer to a specified offset in the current instance, relative to a specified origin.

Parameters

Name Type Default value Description
offset number undefined Byte offset to seek to. Must be a safe, positive integer.
origin SeekOrigin SeekOrigin.Begin Origin from which to seek

Returns

void

Inherited from

SandwichFile.seek


truncate

Protected truncate(length): void

Resizes the current instance to a specific number of bytes.

Parameters

Name Type Description
length number Number of bytes to resize the file to, must be a safe, positive integer.

Returns

void

Inherited from

SandwichFile.truncate


writeBlock

writeBlock(data): void

Writes a block of data to the file represented by the current instance at the current seek position. This will overwrite any existing data at the seek position and append new data to the file if writing past the current end.

Throws

Error Thrown when data is not provided.

Parameters

Name Type Description
data ByteVector ByteVector containing data to the current instance.

Returns

void

Inherited from

SandwichFile.writeBlock


addFileType

Static addFileType(mimeType, constructor, override?): void

Registers the constructor for a subclass of File with the MimeType it is associated with. Optionally, the MimeType can be forcefully overridden if it was already registered.

Parameters

Name Type Default value Description
mimeType string undefined MimeType to register this subclass constructor to.
constructor FileTypeConstructor undefined Constructor for a subclass of File that will be called if a file with a MimeType of mimeType is created.
override boolean false If true and a subclass of File was already registered to mimeType, it will be forcefully overridden. If false, an Error will be thrown if a subclass already registered to the MimeType.

Returns

void

Inherited from

SandwichFile.addFileType


addFileTypeResolver

Static addFileTypeResolver(resolver): void

Registers a FileTypeResolver to the front of the list of file type resolvers.

Parameters

Name Type Description
resolver FileTypeResolver Function to handle resolving a subclass of File from an IFileAbstraction

Returns

void

Inherited from

SandwichFile.addFileTypeResolver


createFromAbstraction

Static createFromAbstraction(abstraction, mimeType?, propertiesStyle?): File

Creates a new instance of a File subclass for a specified file abstraction, MimeType, and property read style.

Parameters

Name Type Default value Description
abstraction IFileAbstraction undefined Object to use when reading/writing from the current instance.
mimeType? string undefined Optional, MimeType to use for determining the subclass of File to return. If omitted, the MimeType will be guessed based on the file's extension.
propertiesStyle ReadStyle ReadStyle.Average Optional, level of detail to use when reading the media information from the new instance. If omitted, Average is used.

Returns

File

New instance of File as read from the specified abstraction.

Inherited from

SandwichFile.createFromAbstraction


createFromPath

Static createFromPath(filePath, mimeType?, propertiesStyle?): File

Creates a new instance of File subclass for a specified file path, MimeType, and property read style.

Parameters

Name Type Default value Description
filePath string undefined Path to the file to read/write.
mimeType? string undefined Optional, MimeType to use for determining the subclass of File to return. If omitted, the MimeType will be guessed based on the file's extension.
propertiesStyle ReadStyle ReadStyle.Average Optional, level of detail to use when reading the media information from the new instance. If omitted Average is used.

Returns

File

New instance of File as read from the specified path.

Inherited from

SandwichFile.createFromPath


removeFileType

Static removeFileType(mimeType): void

Used for removing a file type constructor during unit testing

Parameters

Name Type
mimeType string

Returns

void

Inherited from

SandwichFile.removeFileType


removeFileTypeResolver

Static removeFileTypeResolver(resolver): void

Used for removing a file type resolver during unit testing

Parameters

Name Type
resolver FileTypeResolver

Returns

void

Inherited from

SandwichFile.removeFileTypeResolver