node-taglib-sharp / Exports / AsfFile
This class provides tagging and properties support for Microsoft's ASF files.
-
↳
AsfFile
- corruptionReasons
- fileAbstraction
- hasTags
- isPossiblyCorrupt
- isWritable
- length
- mimeType
- mode
- name
- position
- properties
- tag
- tagTypes
- tagTypesOnDisk
- bufferSize
- dispose
- find
- getTag
- insert
- markAsCorrupt
- preSave
- rFind
- readBlock
- removeBlock
- removeTags
- save
- seek
- truncate
- writeBlock
- addFileType
- addFileTypeResolver
- createFromAbstraction
- createFromPath
- removeFileType
- removeFileTypeResolver
• new AsfFile(file
, propertiesStyle
)
Name | Type |
---|---|
file |
string | IFileAbstraction |
propertiesStyle |
ReadStyle |
• get
corruptionReasons(): string
[]
Reasons for which this file is marked as corrupt.
string
[]
File.corruptionReasons
• get
fileAbstraction(): IFileAbstraction
Gets the IFileAbstraction representing the file.
File.fileAbstraction
• 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.
boolean
File.hasTags
• get
isPossiblyCorrupt(): boolean
Indicates whether this file may be corrupt. Files with unknown corruptions should not be written.
boolean
File.isPossiblyCorrupt
• get
isWritable(): boolean
Indicates whether tags can be written back to the current file.
boolean
File.isWritable
• 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;
number
File.length
• get
mimeType(): string
Gets the MimeType of the file as determined during creation of the instance.
string
File.mimeType
• get
mode(): FileAccessMode
Gets the file access mode in use by the current instance.
File.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.
Name | Type | Description |
---|---|---|
val |
FileAccessMode |
File access mode to change to |
void
File.mode
• get
name(): string
Gets the name of the file as stored in its file abstraction.
string
File.name
• 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
number
File.position
• get
properties(): Properties
Gets the media properties of the file represented by the current instance.
File.properties
• get
tag(): AsfTag
Gets an abstract representation of all tags stored in the current instance.
File.tag
• get
tagTypes(): TagTypes
Gets the tag types contained in the current instance.
File.tagTypes
• get
tagTypesOnDisk(): TagTypes
Gets the tag types contained in the physical file represented by the current instance.
File.tagTypesOnDisk
• set
tagTypesOnDisk(value
): void
Sets the tag types contained in the physical file represented by the current instance.
Name | Type |
---|---|
value |
TagTypes |
void
File.tagTypesOnDisk
• Static
get
bufferSize(): number
Gets the buffer size to use when reading large blocks of data
number
File.bufferSize
▸ dispose(): void
Dispose the current instance. Equivalent to setting the mode to closed.
void
▸ 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.
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. |
number
Index at which the value was found. If not found, -1
is returned.
▸ getTag(type
): Tag
Gets a tag of the specified type from the current instance, optionally creating a new tag if possible.
Name | Type | Description |
---|---|---|
type |
TagTypes |
Type of tag to read. |
▸ 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
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. |
void
▸ markAsCorrupt(reason
): void
Mark the current instance as corrupt. NOTE: Not intended to be used outside of this library.
Name | Type | Description |
---|---|---|
reason |
string |
Reason why this file is considered to be corrupt |
void
▸ Protected
preSave(): void
Prepares to save the file. This must be called at the beginning of every File.save() method.
void
▸ 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.
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. |
number
Index at which the value wa found. If not found, -1
is returned.
▸ 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.
Name | Type | Description |
---|---|---|
length |
number |
Number of bytes to read. |
Object containing the data read from the current instance.
▸ 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.
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. |
void
▸ 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
Name | Type | Description |
---|---|---|
types |
TagTypes |
Bitwise combined TagTypes value containing the tag types to be removed from the file |
void
▸ save(): void
Saves the changes made in the current instance to the file it represents.
void
▸ seek(offset
, origin?
): void
Moves the read/write pointer to a specified offset in the current instance, relative to a specified origin.
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 |
void
▸ Protected
truncate(length
): void
Resizes the current instance to a specific number of bytes.
Name | Type | Description |
---|---|---|
length |
number |
Number of bytes to resize the file to, must be a safe, positive integer. |
void
▸ 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.
Name | Type | Description |
---|---|---|
data |
ByteVector |
ByteVector containing data to the current instance. |
void
▸ 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.
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. |
void
▸ Static
addFileTypeResolver(resolver
): void
Registers a FileTypeResolver to the front of the list of file type resolvers.
Name | Type | Description |
---|---|---|
resolver |
FileTypeResolver |
Function to handle resolving a subclass of File from an IFileAbstraction |
void
▸ Static
createFromAbstraction(abstraction
, mimeType?
, propertiesStyle?
): File
Creates a new instance of a File subclass for a specified file abstraction, MimeType, and property read style.
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. |
New instance of File as read from the specified abstraction.
▸ Static
createFromPath(filePath
, mimeType?
, propertiesStyle?
): File
Creates a new instance of File subclass for a specified file path, MimeType, and property read style.
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. |
New instance of File as read from the specified path.
▸ Static
removeFileType(mimeType
): void
Used for removing a file type constructor during unit testing
Name | Type |
---|---|
mimeType |
string |
void
▸ Static
removeFileTypeResolver(resolver
): void
Used for removing a file type resolver during unit testing
Name | Type |
---|---|
resolver |
FileTypeResolver |
void