node-taglib-sharp-extend
Version:
read and write audio file metadata in nodejs / browser(memory)
1,253 lines (1,245 loc) • 119 kB
text/typescript
import { Buffer } from 'buffer';
/**
* Indicates there the seek operation should begin.
*/
declare enum SeekOrigin {
/**
* Seek should begin at the start of the file.
*/
Begin = 0,
/**
* Seek should begin at the current position in the file.
*/
Current = 1,
/**
* Seek should begin at the end of the file.
*/
End = 2
}
/**
* Interface for a stream, it wraps around a file descriptor to make reading and writing to files
* using node IO a lot easier.
*/
interface IStream {
/**
* Whether or not the stream can be written to
*/
readonly canWrite: boolean;
/**
* Number of bytes currently stored in file this stream connects to
*/
readonly length: number;
/**
* Position within the stream
*/
position: number;
/**
* Closes the stream
*/
close(): void;
/**
* Reads a block of bytes from the current stream and writes the data to a buffer.
* @param buffer When this method returns, contains the specified byte array with the values
* between `offset` and (`offset` + `length` - 1) replaced by
* the characters read from the current stream
* @param offset Zero-based byte offset in `buffer` at which to begin storing data
* from the current stream
* @param length The maximum number of bytes to read
* @returns
* Total number of bytes written to the buffer. This can be less than the
* number of bytes requested if that number of bytes are not currently available or zero if
* the end of the stream is reached before any bytes are read
*/
read(buffer: Uint8Array, offset: number, length: number): number;
/**
* Sets the position within the current stream to the specified value.
* @param offset New position within the stream. this is relative to the `origin`
* parameter and can be positive or negative
* @param origin Seek reference point {@link SeekOrigin}
*/
seek(offset: number, origin: SeekOrigin): void;
/**
* Sets the length of the current current stream to the specified value.
* @param length Number of bytes to set the length of the stream to
*/
setLength(length: number): void;
/**
* Writes a block of bytes to the current stream using data read from a buffer.
* @param buffer Buffer to write data from
* @param bufferOffset Zero-based byte offset in `buffer` at which to begin copying
* bytes to the current stream
* @param length Maximum number of bytes to write
*/
write(buffer: Uint8Array | ByteVector, bufferOffset: number, length: number): number;
}
/**
* This interface provides abstracted access to a file. It permits access to non-standard file
* systems and data retrieval methods.
*/
interface IFileAbstraction {
/**
* Name or identifier used by the implementation
* @remarks
* This value would typically represent a path or URL to be used when identifying
* the file system, but it could be any valid as appropriate for the implementation.
*/
name: string;
/**
* Total size of file
*/
size: number;
/**
* Readable, seekable stream for the file referenced by the current instance.
* @remarks
* This property is typically used when constructing an instance of {@link File}.
* Upon completion of the constructor {@link closeStream} will be called to close the stream.
* If the stream is to be reused after this point, {@link closeStream} should be implemented
* in a way to keep it open.
*/
readStream: IStream;
/**
* Writable, seekable stream for the file referenced by the current instance.
* @remarks
* This property is typically used when saving a file with {@link File.save}. Upon
* completion of the method, {@link closeStream} will be called to close the stream. If the
* stream is to be reused after this point, {@link closeStream} should be implemented in a way
* to keep it open
*/
writeStream: IStream;
/**
* Closes a stream created by the current instance.
* @param stream Stream created by the current instance.
*/
closeStream(stream: IStream): void;
}
/**
* @summary Specifies the text encoding used when converting betweenInclusive a string and a
* {@link ByteVector}.
* @remarks
* This enumeration is used by {@link ByteVector.fromString} and
* {@link ByteVector.toString}
*/
declare enum StringType {
/**
* @summary The string is to be Latin-1 encoded.
*/
Latin1 = 0,
/**
* @summary The string is to be UTF-16 encoded.
*/
UTF16 = 1,
/**
* @summary The string is to be UTF-16BE encoded.
*/
UTF16BE = 2,
/**
* @summary The string is to be UTF-8 encoded.
*/
UTF8 = 3,
/**
* @summary The string is to be UTF-16LE encoded.
*/
UTF16LE = 4,
/**
* @summary The string is to be encoded as a hex string for each byte (eg, 0x00, 0x12, 0xAF).
* Intended to be used for debugging purposes, only.
*/
Hex = 5
}
/**
* Wrapper around a `Uint8Array` that provides functionality for reading and writing byte arrays.
* @remarks
* Implementation of this class uses a single `Uint8Array` to store bytes. Due to
* `Uint8Array`s being fixed length, any operation that inserts or removes values into the
* instance will result in a copy of the internal array being made. If multiple additions will
* be made, rather than using multiple inserts/adds, the {@link ByteVector.concatenate} method
* is provided to group additions/inserts and therefore improve performance.
*
* The original .NET implementation had a ubiquitous `mid` method that would return a subset
* of the bytes in the current instance. In versions <5 of the node port, `mid` would make a
* copy of the subset of the bytes. Since this was frequently done right before reading a
* number or string, this copy was extremely wasteful. In version 5, the `mid` method was
* replaced with `subarray` which behaves identically to `Uint8Array.subarray` and returns
* an instance that is a 'view' of an existing instance - no copying involved. However, all
* write operations make copies, instances that are backed by 'views' may waste memory by
* referencing a `Uint8Array` that is much larger than the view.
*
* With this in mind, best practices for using `ByteVectors`:
* * Calling {@link ByteVector.subarray} is cheap, use it when possible
* * If storing a subset of a `ByteVector`, store a copy with {@link ByteVector.toByteVector}
* * If building a `ByteVector`, use {@link ByteVector.concatenate} when possible
* * If the instance should be immutable, use {@link ByteVector.makeReadOnly}
*/
declare class ByteVector {
private static readonly CRC_TABLE;
/**
* Contains a one byte text delimiter
*/
private static readonly TD1;
/**
* Contains a two byte text delimiter
*/
private static readonly TD2;
private _bytes;
private _isReadOnly;
private constructor();
/**
* Creates a {@link ByteVector} from a collection of bytes, byte arrays, and byte vectors. This
* method is better to use when a known quantity of byte vectors will be concatenated together,
* since doing multiple calls to {@link ByteVector.addByteVector} results in the entire byte
* vector being copied for each call.
* @param vectors ByteVectors, byte arrays, or straight bytes to concatenate together into a
* new {@link ByteVector}
* @returns
* Single byte vector with the contents of the byte vectors in `vectors` concatenated
* together
*/
static concatenate(...vectors: Array<Uint8Array | ByteVector | number | undefined>): ByteVector;
/**
* Creates an empty {@link ByteVector}
*/
static empty(): ByteVector;
/**
* Creates a {@link ByteVector} from a base64 string.
* @param str Base64 string to convert into a byte vector
*/
static fromBase64String(str: string): ByteVector;
/**
* Creates a {@link ByteVector} from a `Uint8Array` or `Buffer`
* @param bytes Uint8Array of the bytes to put in the ByteVector
* @param length Optionally, number of bytes to read. If this is not provided, it will default
* to the full length of `bytes`. If it is less than the length of `bytes`, `bytes` will be
* copied into the {@link ByteVector}.
*/
static fromByteArray(bytes: Uint8Array | Buffer | number[], length?: number): ByteVector;
/**
* Creates a new instance by reading in the contents of a specified file abstraction.
* @param abstraction File abstraction to read
*/
static fromFileAbstraction(abstraction: IFileAbstraction): ByteVector;
/**
* Creates a 4 byte {@link ByteVector} with a signed 32-bit integer as the data
* @param value Signed 32-bit integer to use as the data.
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromInt(value: number, isBigEndian?: boolean): ByteVector;
/**
* Creates a ByteVector using the contents of an TagLibSharp-node stream as the contents. This
* method reads from the current offset of the stream, not the beginning of the stream
* @param stream TagLibSharp-node internal stream object
*/
static fromInternalStream(stream: IStream): ByteVector;
/**
* Creates an 8 byte {@link ByteVector} with a signed 64-bit integer as the data
* @param value Signed 64-bit integer to use as the data. If using a `bigint`, it must fit
* within 8 bytes. If using a `number`, it must be a safe integer.
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromLong(value: bigint | number, isBigEndian?: boolean): ByteVector;
/**
* Creates a 1 byte {@link ByteVector} with an unsigned 8-bit integer as the data
* @param value Unsigned 8-bit integer to use as the data.
*/
static fromByte(value: number): ByteVector;
/**
* Creates a 2 byte {@link ByteVector} with a signed 16-bit integer as the data
* @param value Signed 16-bit integer to use as the data.
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromShort(value: number, isBigEndian?: boolean): ByteVector;
/**
* Creates a {@link ByteVector} of a given length with a given value for all the elements
* @param size Length of the ByteVector. Must be a positive safe integer
* @param fill Byte value to initialize all elements to. Must be a positive 8-bit integer
*/
static fromSize(size: number, fill?: number): ByteVector;
/**
* Creates {@link ByteVector} with the contents of a stream as the data. The stream will be read
* to the end before the ByteVector is returned.
* @param readStream Readable stream that will be read in entirety.
*/
static fromStream(readStream: NodeJS.ReadableStream): Promise<ByteVector>;
/**
* Creates {@link ByteVector} with the byte representation of a string as the data.
* @param text String to store in the ByteVector
* @param type StringType to use to encode the string. If {@link StringType.UTF16} is used, the
* string will be encoded as UTF16-LE.
* @param length Number of characters from the string to store in the ByteVector. Must be a
* positive 32-bit integer.
*/
static fromString(text: string, type: StringType, length?: number): ByteVector;
/**
* Creates a 4 byte {@link ByteVector} with a positive 32-bit integer as the data
* @param value Positive 32-bit integer to use as the data
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromUint(value: number, isBigEndian?: boolean): ByteVector;
/**
* Creates an 8 byte {@link ByteVector} with a positive 64-bit integer as the data
* @param value Positive 64-bit integer to use as the data. If using a `bigint` it must fit
* within 8 bytes.
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromUlong(value: bigint | number, isBigEndian?: boolean): ByteVector;
/**
* Creates a 2 byte {@link ByteVector} with a positive 16-bit integer as the data
* @param value Positive 16-bit integer to use as the data.
* @param isBigEndian If `true`, `value` will be stored in big endian format. If `false`,
* `value` will be stored in little endian format
*/
static fromUshort(value: number, isBigEndian?: boolean): ByteVector;
/**
* Calculates the CRC32 of the current instance.
*/
get checksum(): number;
/**
* Whether the current instance has 0 bytes stored.
*/
get isEmpty(): boolean;
/**
* Whether the current instance is read-only. If `true`, any call that will modify the instance
* will throw.
*/
get isReadOnly(): boolean;
/**
* Whether the current instance is a 'view' of another byte vector.
*/
get isView(): boolean;
/**
* Number of bytes currently in this instance.
*/
get length(): number;
/**
* Gets the appropriate length null-byte text delimiter for the specified `type`.
* @param type String type to get delimiter for
*/
static getTextDelimiter(type: StringType): ByteVector;
/**
* Compares two byte vectors. Returns a numeric value
* @param a Byte vector to compare against `b`
* @param b Byte vector to compare against `a`
* @returns
* `0` if the two vectors are the same. Any other value indicates the two are
* different. If the two vectors differ by length, this will be the length of `a` minus the
* length of `b`. If the lengths are the same it will be the difference between the first
* element that differs.
*/
static compare(a: ByteVector, b: ByteVector): number;
/**
* Returns `true` if the contents of the two {@link ByteVector}s are identical, returns `false`
* otherwise
* @param first ByteVector to compare with `second`
* @param second ByteVector to compare with `first`
*/
static equals(first: ByteVector, second: ByteVector): boolean;
/**
* Gets iterator for iterating over bytes in the current instance.
*/
[Symbol.iterator](): Iterator<number>;
/**
* Adds a single byte to the end of the current instance
* @param byte Value to add to the end of the ByteVector. Must be positive 8-bit integer.
*/
addByte(byte: number): void;
/**
* Adds an array of bytes to the end of the current instance
* @param data Array of bytes to add to the end of the ByteVector
* @param length Number of elements from `data` to copy into the current instance
*/
addByteArray(data: Uint8Array, length?: number): void;
/**
* Adds a {@link ByteVector} to the end of this ByteVector
* @param data ByteVector to add to the end of this ByteVector
*/
addByteVector(data: ByteVector): void;
/**
* Removes all elements from this {@link ByteVector}
* @remarks This method replaces the internal byte array with a new one.
*/
clear(): void;
/**
* Determines if `pattern` exists at a certain `offset` in this byte vector.
* @param pattern ByteVector to search for at in this byte vector
* @param offset Position in this byte vector to search for the pattern. If omitted, defaults
* to `0`
*/
containsAt(pattern: ByteVector, offset?: number): boolean;
/**
* Compares the current instance to another byte vector. Returns a numeric result.
* @param other Other byte vector to compare against the current instance.
*/
compareTo(other: ByteVector): number;
/**
* Determines whether this byte vector ends with the provided `pattern`.
* @param pattern ByteVector to look for at the end of this byte vector
*/
endsWith(pattern: ByteVector): boolean;
/**
* Determines whether this byte vector ends with a part of the `pattern`.
* NOTE: if this instance ends with `pattern` perfectly, it must end with n-1 or
* fewer bytes.
* @param pattern ByteVector to look for at the end of this byte vector
*/
endsWithPartialMatch(pattern: ByteVector): number;
/**
* Determines if this instance has identical contents to the `other` instance.
* @param other Other instance to compare against the current instance.
*/
equals(other: ByteVector): boolean;
/**
* Searches this instance for the `pattern`. Returns the index of the first instance
* of the pattern, or `-1` if it was not found. Providing a `byteAlign` requires the
* pattern to appear at an index that is a multiple of the byteAlign parameter.
* Example: searching "abcd" for "ab" with byteAlign 1 will return 0. Searching "abcd" for
* "ab" with byteAlign 2 will return 1. Searching "00ab" for "ab" with byteAlign 2 will return
* 2. Searching "0abc" with byteAlign 2 will return -1.
* @param pattern Pattern of bytes to search this instance for
* @param byteAlign Optional, byte alignment the pattern much align to
*/
find(pattern: ByteVector, byteAlign?: number): number;
/**
* Gets the byte at the given `index`.
* @param index Element index to return
*/
get(index: number): number;
/**
* Gets the index of the first occurrence of the specified value.
* @param item A byte to find within the current instance.
* @returns
* An integer containing the first index at which the value was found, or -1 if it was not
* found
*/
indexOf(item: number): number;
/**
* Makes the current instance read-only, causing any call that would modify it or allow it to
* be modified to throw.
*/
makeReadOnly(): this;
/**
* Searches this instance for the `pattern` occurring after a given offset. Returns the index
* of the first instance of the pattern, relative to the start of the array, or `-1` if it was
* not found. Providing a `byteAlign` requires the pattern to appear at an index that is a
* multiple of the byteAlign parameter. Example: searching "abcd" for "ab" with byteAlign 1
* will return 0. Searching "abcd" for "ab" with byteAlign 2 will return 1. Searching "00ab"
* for "ab" with byteAlign 2 will return 2. Searching "0abc" with byteAlign 2 will return -1.
* @param pattern Pattern of bytes to search this instance for
* @param offset Index into the instance to begin searching for `pattern`
* @param byteAlign Optional, byte alignment the pattern much align to
*/
offsetFind(pattern: ByteVector, offset: number, byteAlign?: number): number;
/**
* Resizes this instance to the length specified in `size`. If the desired size is
* longer than the current length, it will be filled with the byte value in
* `padding`. If the desired size is shorter than the current length, bytes will be
* removed.
* @param size Length of the byte vector after resizing. Must be unsigned 32-bit integer
* @param padding Byte to fill any excess space created after resizing
*/
resize(size: number, padding?: number): void;
/**
* Finds a byte vector by searching from the end of this instance and working towards the
* beginning of this instance. Returns the index of the first instance of the pattern, or `-1`
* if it was not found. Providing a `byteAlign` requires the pattern to appear at an
* index that is a multiple of the byteAlign parameter.
* Example: searching "abcd" for "ab" with byteAlign 1 will return 0. Searching "abcd" for
* "ab" with byteAlign 2 will return 1. Searching "00ab" for "ab" with byteAlign 2 will return
* 2. Searching "0abc" with byteAlign 2 will return -1.
* @param pattern Pattern of bytes to search this instance for
* @param byteAlign Optional, byte alignment the pattern must align to
*/
rFind(pattern: ByteVector, byteAlign?: number): number;
/**
* Sets the value at a specified index
* @param index Index to set the value of
* @param value Value to set at the index. Must be a valid integer betweenInclusive 0x0 and 0xff
*/
set(index: number, value: number): void;
/**
* Changes the contents of the current instance by removing or replacing existing elements
* and/or adding new elements.
* @param start Index at which to start changing the array. Must be less than the length of
* the instance
* @param deleteCount Number of elements in the array to remove from start. If greater than
* the remaining length of the element, it will be capped at the remaining length
* @param items Elements to add to the array beginning from start. If omitted, the method will
* only remove elements from the current instance.
*/
splice(start: number, deleteCount: number, items?: ByteVector | Uint8Array | number[]): void;
/**
* Splits this byte vector into a list of byte vectors using a separator
* @param separator Object to use to split this byte vector
* @param byteAlign Byte align to use when splitting. in order to split when a pattern is
* encountered, the index at which it is found must be divisible by this value.
* @param max Maximum number of objects to return or 0 to not limit the number. If that number
* is reached, the last value will contain the remainder of the file even if it contains
* more instances of `separator`.
* @returns ByteVector[] The split contents of the current instance
*/
split(separator: ByteVector, byteAlign?: number, max?: number): ByteVector[];
/**
* Returns a window over the current instance.
* @param startIndex Offset into this instance where the comprehension begins
* @param length Number of elements from the instance to include. If omitted, defaults to the
* remainder of the instance
*/
subarray(startIndex: number, length?: number): ByteVector;
/**
* Checks whether a pattern appears at the beginning of the current instance.
* @param pattern ByteVector containing the pattern to check for in the current instance.
* @returns
* `true` if the pattern was found at the beginning of the current instance, `false`
* otherwise.
*/
startsWith(pattern: ByteVector): boolean;
/**
* Returns the current instance as a base64 encoded string.
*/
toBase64String(): string;
/**
* Returns the bytes for the instance. Don't use it unless you need to.
* @internal
* @deprecated DON'T USE IT UNLESS YOU HAVE NO CHOICE.
*/
toByteArray(): Uint8Array;
/**
* Returns a writable copy of the bytes represented by this instance.
* @remarks This is a **copy** of the data. Use sparingly.
*/
toByteVector(): ByteVector;
/**
* Converts the first eight bytes of the current instance to a double-precision floating-point
* value.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format).
* @throws Error If there are less than eight bytes in the current instance.
* @returns A double value containing the value read from the current instance.
*/
toDouble(mostSignificantByteFirst?: boolean): number;
/**
* Converts the first four bytes of the current instance to a single-precision floating-point
* value.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format).
* @throws Error If there are less than four bytes in the current instance
* @returns A float value containing the value read from the current instance.
*/
toFloat(mostSignificantByteFirst?: boolean): number;
/**
* Converts the first four bytes of the current instance to a signed integer. If the current
* instance is less than four bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns A signed integer value containing the value read from the current instance
*/
toInt(mostSignificantByteFirst?: boolean): number;
/**
* Converts the first eight bytes of the current instance to a signed long. If the current
* instance is less than eight bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns
* A signed long value containing the value read from the current instance,
* represented as a BigInt due to JavaScript's 52-bit integer limitation.
*/
toLong(mostSignificantByteFirst?: boolean): bigint;
/**
* Converts the first two bytes of the current instance to a signed short. If the current
* instance is less than two bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns A signed short value containing the value read from the current instance
*/
toShort(mostSignificantByteFirst?: boolean): number;
/**
* Converts a portion of the current instance to a string using a specified encoding
* @param type Value indicating the encoding to use when converting to a string.
* @returns String containing the converted bytes
*/
toString(type: StringType): string;
/**
* Converts the current instance into an array of strings starting at the specified offset and
* using the specified encoding, assuming the values are `null` separated and limiting it to a
* specified number of items.
* @param type A {@link StringType} value indicating the encoding to use when converting
* @param count Value specifying a limit to the number of strings to create. Once the limit has
* been reached, the last string will be filled by the remainder of the data
* @returns Array of strings containing the converted text.
*/
toStrings(type: StringType, count?: number): string[];
/**
* Converts the first four bytes of the current instance to an unsigned integer. If the current
* instance is less than four bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns An unsigned integer value containing the value read from the current instance
*/
toUint(mostSignificantByteFirst?: boolean): number;
/**
* Converts the first eight bytes of the current instance to an unsigned long. If the current
* instance is less than eight bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns
* An unsigned short value containing the value read from the current instance,
* represented as a BigInt due to JavaScript's 32-bit integer limitation
*/
toUlong(mostSignificantByteFirst?: boolean): bigint;
/**
* Converts the first two bytes of the current instance to an unsigned short. If the current
* instance is less than two bytes, the most significant bytes will be filled with 0x00.
* @param mostSignificantByteFirst If `true` the most significant byte appears first (big
* endian format)
* @returns An unsigned short value containing the value read from the current instance
*/
toUshort(mostSignificantByteFirst?: boolean): number;
private getSizedDataView;
private throwIfReadOnly;
}
/**
* Error class that indicates the file is likely corrupt.
*/
declare class CorruptFileError extends Error {
constructor(msg?: string);
}
/**
* Error class that indicates a piece of functionality is not implemented in the current version.
*/
declare class NotImplementedError extends Error {
constructor(message?: string);
}
/**
* Interface for objects that can (and should) be disposed after they are no longer needed.
*/
interface IDisposable {
/**
* Disposes the current instance.
*/
dispose(): void;
}
/**
* Interface for objects that can be lazily loaded.
*/
interface ILazy {
/**
* Gets whether the object has been loaded.
*/
isLoaded: boolean;
/**
* Loads the object.
*/
load(): void;
}
/**
* Indicates the types o media represented by a {@link ICodec} or {@link Properties}. These values
* can be combined to represent multiple media types.
*/
declare enum MediaTypes {
/**
* No media is present
*/
None = 0,
/**
* Audio is present
*/
Audio = 1,
/**
* Video is present
*/
Video = 2,
/**
* A photo is present
*/
Photo = 4,
/**
* Text is present
*/
Text = 8,
/**
* Lossless audio is present. This also implies audio is present.
*/
LosslessAudio = 17
}
/**
* Interface that provides basic information common to all media codecs
*/
interface ICodec {
/**
* Gets a text description of the media represented by the current instance.
*/
description: string;
/**
* Duration of the media in milliseconds represented by the current instance.
* @TODO Ensure milliseconds is the right way to interpret this field
*/
durationMilliseconds: number;
/**
* Types of media represented by the current instance, bitwise combined.
*/
mediaTypes: MediaTypes;
}
/**
* Interface that inherits the common codec information and adds audio-specific information.
* When dealing with an {@link ICodec}, if {@link ICodec.mediaTypes} contains
* {@link MediaTypes.Audio}, it is safe to assume that the object also inherits {@link IAudioCodec}
* and can be recast without issue.
*/
interface IAudioCodec extends ICodec {
/**
* Bitrate of the audio in kilobits per second represented by the current instance.
*/
audioBitrate: number;
/**
* Number of channels in the audio represented by the current instance.
*/
audioChannels: number;
/**
* Sample rate of the audio represented by the current instance.
*/
audioSampleRate: number;
}
/**
* This interface provides information specific to lossless audio codecs.
* When dealing with an {@link ICodec}, if {@link ICodec.mediaTypes} contains
* {@link MediaTypes.LosslessAudio}, it is safe to assume that the object also inherits
* {@link ILosslessAudioCodec} and can be recast without issue.
*/
interface ILosslessAudioCodec extends IAudioCodec {
/**
* Number of bits per sample in the audio represented by the current instance.
*/
bitsPerSample: number;
}
/**
* Interface that inherits the common codec information and adds video-specific information.
* When dealing with an {@link ICodec}, if {@link ICodec.mediaTypes} contains
* {@link MediaTypes.Video}, it is safe to assume that the object also inherits {@link IVideoCodec}
* and can be recast without issue.
*/
interface IVideoCodec extends ICodec {
/**
* Height of the video in pixels represented by the current instance.
*/
videoHeight: number;
/**
* Width of the video in pixels represented by the current instance.
*/
videoWidth: number;
}
/**
* Interface that inherits the common codec information and adds photo-specific information.
* When dealing with an {@link ICodec}, if {@link ICodec.mediaTypes} contains
* {@link MediaTypes.Photo}, it is safe to assume that the object also inherits {@link IPhotoCodec}
* and can be recast without issue.
*/
interface IPhotoCodec extends ICodec {
/**
* Height of the photo in pixels represented by the current instance.
*/
photoHeight: number;
/**
* Format-specific quality indicator of the photo represented by the current instance.
* A value of `0` means there was no quality indicator for the format or file.
*/
photoQuality: number;
/**
* Width of the photo in pixels represented by the current instance.
*/
photoWidth: number;
}
declare class Properties implements ILosslessAudioCodec, IVideoCodec, IPhotoCodec {
private readonly _codecs;
private readonly _duration;
/**
* Constructs and initializes a new instance of {@link Properties} with the specified codecs and
* duration.
* @param durationMilli Duration of the media in milliseconds or 0 if the duration is to be
* read from the codecs.
* @param codecs Array of codecs to be used in the new instance.
*/
constructor(durationMilli?: number, codecs?: ICodec[]);
/**
* Gets the codecs contained in the current instance.
* @remarks
* The list of codecs should not be modified. As such, the returned codec list is a
* copy of codec list stored in this instance.
*/
get codecs(): ICodec[];
/**
* Gets a string description of the media represented by the current instance. Values are
* joined by semicolons.
*/
get description(): string;
/**
* Gets the duration of the media represented by the current instance. If the value was set in
* the constructor, that value is returned, otherwise the longest codec duration is used.
*/
get durationMilliseconds(): number;
/**
* Gets the types of media represented by the current instance.
*/
get mediaTypes(): MediaTypes;
/**
* Gets the bitrate of the audio represented by the current instance. This value is equal to
* the first non-zero audio bitrate, or zero if no codecs with audio information were found.
*/
get audioBitrate(): number;
/**
* Gets the number of channels in the audio represented by the current instance.
*/
get audioChannels(): number;
/**
* Gets the sample rate of the audio represented by the current instance. This value is equal
* to the first non-zero audio bitrate, or zero if no audio codecs were found.
*/
get audioSampleRate(): number;
/**
* Gets the number of bits per sample in the audio represented by the current instance. This
* value is equal to the first non-zero quantization, or zero if no lossless audio codecs were
* found in the current instance.
*/
get bitsPerSample(): number;
/**
* Gets the height of the photo in pixels represented by the current instance.
*/
get photoHeight(): number;
/**
* Gets the format-specific quality identifier of the photo represented by the current
* instance. A value of `0` means that there was no quality indicator for the format or file.
*/
get photoQuality(): number;
/**
* Gets the width of the photo in pixels represented by the current instance.
*/
get photoWidth(): number;
/**
* Gets the height of the video represented by the current instance.
* This value is equal to the first non-zero video height;
*/
get videoHeight(): number;
/**
* Gets the width of the video represented by the current instance.
* This value is equal to the first non-zero video height.
*/
get videoWidth(): number;
private findCodecProperty;
}
/**
* The type of content appearing in an {@link IPicture} instance.
*/
declare enum PictureType {
/**
* @summary The picture is of a type other than those specified.
*/
Other = 0,
/**
* @summary The picture is a 32x32 PNG image that should be used when displaying the file in a browser.
*/
FileIcon = 1,
/**
* @summary The picture is of an icon different from {@link FileIcon}
*/
OtherFileIcon = 2,
/**
* @summary The picture is of the front cover of the album.
*/
FrontCover = 3,
/**
* @summary The picture is of the back cover of the album.
*/
BackCover = 4,
/**
* @summary The picture is of a leaflet page including with the album.
*/
LeafletPage = 5,
/**
* @summary The picture is of the album or disc itself.
*/
Media = 6,
/**
* @summary The picture is of the lead artist or soloist.
*/
LeadArtist = 7,
/**
* @summary The picture is of the artist or performer.
*/
Artist = 8,
/**
* @summary The picture is of the conductor.
*/
Conductor = 9,
/**
* @summary The picture is of the band or orchestra.
*/
Band = 10,
/**
* @summary The picture is of the composer.
*/
Composer = 11,
/**
* @summary The picture is of the lyricist or text writer.
*/
Lyricist = 12,
/**
* @summary The picture is of the recording location or studio.
*/
RecordingLocation = 13,
/**
* @summary The picture is one taken during the track's recording.
*/
DuringRecording = 14,
/**
* @summary The picture is one taken during the track's performance.
*/
DuringPerformance = 15,
/**
* @summary The picture is a capture from a movie screen.
*/
MovieScreenCapture = 16,
/**
* @summary The picture is of a large, colored fish.
*/
ColoredFish = 17,
/**
* @summary The picture is an illustration related to the track.
*/
Illustration = 18,
/**
* @summary The picture contains the logo of the band or performer.
*/
BandLogo = 19,
/**
* @summary The picture is the logo of the publisher or record
*/
PublisherLogo = 20,
/**
* @summary In fact, this is not a Picture, but another file-type.
*/
NotAPicture = 255
}
/**
* Interface that provides generic information about a picture, including its contents, as used by
* various formats.
*/
interface IPicture {
/**
* Gets and sets the mime-type of the picture data stored in the current instance.
*/
mimeType: string;
/**
* Gets and sets the type of the content visible in the picture stored in the current instance.
*/
type: PictureType;
/**
* Gets and sets a filename of the picture stored in the current instance. Optional.
*/
filename: string;
/**
* Gets and sets a description of the picture stored in the current instance. Optional.
*/
description: string;
/**
* Gets and sets the picture data stored in the current instance.
*/
data: ByteVector;
}
/**
* This class implements {@link IPicture} and provides a mechanism for loading pictures from files.
*/
declare class Picture implements IPicture {
private static readonly EXTENSION_TO_MIMETYPES;
private constructor();
/**
* Constructs and initializes a new instance from the data provided. The data is processed to
* discover the type of the picture.
* @param data Raw bytes of the picture to store in the instance. Cannot be falsey
*/
static fromData(data: ByteVector): Picture;
/**
* Constructs a new instance with the data provided. No processing of the data is done.
* @param data Raw bytes of the picture to store in the instance. Cannot be falsey
* @param type Type of the picture. Cannot be null or undefined
* @param mimeType MimeType of the picture. Cannot be falsey
* @param description Description of the picture. Cannot be null or undefined
*/
static fromFullData(data: ByteVector, type: PictureType, mimeType: string, description: string): Picture;
/**
* Constructs and initializes a new instance from a file abstraction. The description and type
* of the file are determined by the name of the abstraction.
* @param abstraction File abstraction to load the picture from.
*/
static fromFileAbstraction(abstraction: IFileAbstraction): Picture;
/** @inheritDoc */
data: ByteVector;
/** @inheritDoc */
description: string;
/** @inheritDoc */
filename: string;
/** @inheritDoc */
mimeType: string;
/**
* Gets and sets the type of the content visible in the picture stored in the current instance.
*/
type: PictureType;
/**
* Retrieve a mimetype from raw file data by reading the first few bytes of the file. Less
* accurate than {@link getExtensionFromMimeType} since this is limited to image file types.
* @param data Bytes of the file to read to identify the extension
* @returns
* Extension of the file with dot at the beginning based on the first few bytes
* of the data. If the extension cannot be determined, `undefined` is returned
*/
static getExtensionFromData(data: ByteVector): string;
/**
* Gets the file extension for a specific mimetype.
* @param mime Mimetype to look up the extension for
* @returns
* Extension of the file based on the mimetype with a dot at the beginning. If
* the extension cannot be determined, `undefined` is returned
*/
static getExtensionFromMimeType(mime: string): string;
/**
* Gets the mimetype of a file based on its extension. If the mimetype cannot be determined, it
* is assumed to be a basic binary file.
* @param name Filename with extension or just the extension of the file
* @returns
* Mimetype of the file based on the extension. If mimetype cannot be
* determined, application/octet-stream is returned.
*/
static getMimeTypeFromFilename(name: string): string;
}
/**
* This class implements {@link IPicture} and provides mechanisms for loading pictures from files.
* Contrary to {@link Picture}, a reference to a file where the picture is located can be given and
* the picture is lazily loaded from the file, meaning that it will be read from the file only when
* needed. This saves time and memory if the picture loading is not required.
*/
declare class PictureLazy implements IPicture, ILazy {
private _data;
private _description;
private _file;
private _filename;
private _mimeType;
private _streamOffset;
private _streamSize;
private _type;
private constructor();
/**
* Constructs a new picture using data that's already been read into memory. The content
* will not be lazily loaded.
* @param data ByteVector Object containing picture data
*/
static fromData(data: ByteVector): PictureLazy;
/**
* Constructs a new instance from a file abstraction. The content will be lazily loaded.
* @param file File abstraction containing the file to read
* @param offset Index into the file where the picture is located, must be a 32-bit integer
* @param size Optionally, size of the picture in bytes. If omitted, all bytes of file will be
* read when lazily loaded. Must be a 32-bit integer or `undefined`
*/
static fromFile(file: IFileAbstraction, offset: number, size?: number): PictureLazy;
/** @inheritDoc */
get data(): ByteVector;
/** @inheritDoc */
set data(value: ByteVector);
/** @inheritDoc */
get description(): string;
/** @inheritDoc */
set description(value: string);
/** @inheritDoc */
get filename(): string;
/** @inheritDoc */
set filename(value: string);
/** @inheritDoc */
get isLoaded(): boolean;
/** @inheritDoc */
get mimeType(): string;
/** @inheritDoc */
set mimeType(value: string);
/** @inheritDoc */
get type(): PictureType;
/** @inheritDoc */
set type(value: PictureType);
/** @inheritDoc */
load(): void;
}
/**
* Indicates the tag types used by a file.
*/
declare enum TagTypes {
/**
* @summary No tag types.
*/
None = 0,
/**
* @summary Xiph Vorbis Comment
*/
Xiph = 1,
/**
* @summary ID3v1 Tag
*/
Id3v1 = 2,
/**
* @summary ID3v2 Tag
*/
Id3v2 = 4,
/**
* @summary APE Tag
*/
Ape = 8,
/**
* @summary Apple's ILST Tag Format
*/
Apple = 16,
/**
* @summary ASF Tag
*/
Asf = 32,
/**
* @summary Standard RIFF INFO List Tag
*/
RiffInfo = 64,
/**
* @summary RIFF Movie ID List Tag
*/
MovieId = 128,
/**
* @summary DivX Tag
*/
DivX = 256,
/**
* @summary FLAC Metadata Block Pictures
*/
FlacPictures = 512,
/**
* @summary TIFF IFD Tag
*/
TiffIFD = 1024,
/**
* @summary XMP Tag
*/
XMP = 2048,
/**
* @summary Jpeg Comment Tag
*/
JpegComment = 4096,
/**
* @summary Gif Comment Tag
*/
GifComment = 8192,
/**
* @summary native PNG keywords
*/
Png = 16384,
/**
* @summary IPTC-IIM tag
*/
IPTCIIM = 32768,
/**
* @summary Audible Metadata Blocks Tag
*/
AudibleMetadata = 65536,
/**
* @summary Matroska native tag
*/
Matroska = 131072,
/**
* @summary All tag types.
*/
AllTags = 4294967295
}
/**
* Abstract class that provides generic access to standard tag features. All tag types will extend
* this class.
* Because not every tag type supports the same features, it may be useful to check that the value
* is stored by re-reading the property after it is set.
*/
declare abstract class Tag {
/**
* Gets the tag types contained in the current instance. A bit wise combined {@link TagTypes}
* containing the tag types contained in the current instance.
* @remarks
* For a standard tag, the value should be intuitive. For example, Id3v2Tag objects have
* a value of {@link TagTypes.Id3v2}. However, for CombinedTag type objects, they may
* contain multiple or no types.
*/
abstract tagTypes: TagTypes;
/**
* Gets the size of the tag in bytes on disk as it was read from disk.
*/
abstract get sizeOnDisk(): number;
/**
* Gets the title for the media described by the current instance.
* @remarks
* The title is most commonly the name of the song, episode or a movie title. For example
* "Time Won't Me Go" (a song by The Bravery), "Three Stories" (an episode of House MD), or
* "Fear and Loathing In Las Vegas" (a movie).
* @returns
* Title of the media described by the current instance or `undefined` if no value is
* present.
*/
get title(): string;
/**
* Sets the title for the media described by the current instance.
*
* The title is most commonly the name of the song, episode or a movie title. For example
* "Time Won't Me Go" (a song by The Bravery), "Three Stories" (an episode of House MD), or
* "Fear and Loathing In Las Vegas" (a movie).
*
* @param value Title of the media described by the current instance or `undefined` if no value
* is present.
*/
set title(value: string);
/**
* Gets the sortable name for the title of the media described by the current instance.
*
* Possibly used to sort compilations or episodic content.
*
* @returns
* Sortable name of the media described by the current instance or `undefined` if no
* value is present
*/
get titleSort(): string;
/**
* Sets the sortable name for the title of the media described by the current instance.
*
* Possibly used to sort compilations or episodic content.
*
* @param value Sortable name of the media described by the current instance or `undefined` if
* no value is present
*/
set titleSort(value: string);
/**
* Gets a description, one-line. It represents the tagline of the vide/music.
*
* This field gives a nice/short precision to the title, which is typically below the
* title on the front cover of the media. For example for "Ocean's 13", this would be
* "Revenge is a funny thing".
*
* @returns
* Subtitle of the media represented by the current instance or `undefined` if no
* value is present
*/
get subtitle(): string;
/**
* Sets a description, one-line. It represents the tagline of the vide/music.
*
* This field gives a nice/short precision to the title, which is typically below the
* title on the front cover of the media. For example for "Ocean's 13", this would be
* "Revenge is a funny thing".
*
* @param value Subtitle of the media represented by the current instance or `undefined` if no
* value is present
*/
set subtitle(value: string);
/**
* Gets a short description of the media. For music, this could be the comment that the artist
* made of his/her work. For a video, this should be a short summary of the story/plot, but
* generally no spoliers. This should give the impression of what to expect in the media.
*
* This is especially relevant for a movie. For example, for "Fear and Loathing in Las
* Vegas", this could be "An oddball journalist and his psychopathic lawyer trav