added media class and packer to handle it

This commit is contained in:
Dolan
2017-03-25 21:50:33 +00:00
parent 30b21217a9
commit 5db2503e7b
2 changed files with 55 additions and 1 deletions

40
ts/media/index.ts Normal file
View File

@ -0,0 +1,40 @@
import * as fs from "fs";
import * as path from "path";
interface IData {
referenceId: number;
stream: fs.ReadStream;
path: string;
fileName: string;
}
export class Media {
private map: Map<string, IData>;
constructor() {
this.map = new Map<string, IData>();
}
public getMedia(key: string): IData | undefined {
return this.map.get(key);
}
public addMedia(key: string, filePath: string): void {
this.map.set(key, {
referenceId: this.map.values.length,
stream: fs.createReadStream(filePath),
path: filePath,
fileName: path.basename(filePath),
});
}
public get array(): IData[] {
const array = new Array<IData>();
this.map.forEach((data) => {
array.push(data);
});
return array;
}
}