import EndTag from "./endTag"; import SandwichTag from "./sandwichTag"; import StartTag from "./startTag"; import { File, ReadStyle } from "../file"; import { IFileAbstraction } from "../fileAbstraction"; import { Properties } from "../properties"; import { Tag, TagTypes } from "../tag"; /** * Interface for a sandwich file. */ export interface ISandwichFile { /** * Gets the position at which the media content of this file ends. */ readonly mediaEndPosition: number; /** * Gets the position at which the media content of this file starts. */ readonly mediaStartPosition: number; } /** * Abstract class that provides tagging and properties for files that can have tags at the * beginning and/or end of the file. The tags are added generically and are not part of the media * format. As such, the tags sandwich the media. * @remarks * This was called `NonContainer` in the original .NET implementation, implying that files * utilizing this pattern could not be containers. This is not true - MPEG containers, for * example, use this pattern. Therefore, the name was changed to better represent the situation. */ export default abstract class SandwichFile extends File implements ISandwichFile { private readonly _properties; private readonly _tag; private _mediaEndPosition; private _mediaStartPosition; /** * Constructs and initializes a new instance based on the provided file. * @param fileToRead File to read tags from * @param readStyle How detailed the file read should be * @param defaultTagMappingTable Mapping indicating where default tags should be created in the * file. If `true` is returned by the function (value of the map), a default tag of the tag * type (key of the map) will be stored at the end of the file. This is only honored if the * file does not already contain a tag of that type and the tag is specified in * `defaultTags`. * @param defaultTags Tags to create on the file if it does not already contain them * @protected */ protected constructor(fileToRead: IFileAbstraction | string, readStyle: ReadStyle, defaultTagMappingTable: Map boolean>, defaultTags: TagTypes); /** * Gets the collection of tags appearing at the end of the file. */ protected get endTag(): EndTag; /** * Gets the collection of tags appearing at the start of the file. */ protected get startTag(): StartTag; /** @inheritDoc */ get mediaEndPosition(): number; /** @inheritDoc */ get mediaStartPosition(): number; /** * Gets an abstract representation of all tags stored in the current instance. */ get tag(): SandwichTag; /** * Gets the media properties of the file represented by the current instance. */ get properties(): Properties; /** @inheritDoc */ getTag(type: TagTypes, create: boolean): Tag; /** @inheritDoc */ removeTags(types: TagTypes): void; /** @inheritDoc */ save(): void; /** * Reads the properties of the file. * @param readStyle Indicates what degree of accuracy the file properties are read, if at all. * @protected */ protected abstract readProperties(readStyle: ReadStyle): Properties; }