aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/blob.ts
blob: ef9f9ab0d7e5bae0db2d8ea42861ff00cae26e71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { BlobError, createError } from "./error";
import { Tree } from "./tree";
import { BlobTreeEntry } from "./tree_entry";

export class Blob {
	private _tree_entry: BlobTreeEntry;

	public path;

	constructor(entry: BlobTreeEntry, path: string) {
		this._tree_entry = entry;

		this.path = path;
	}

	public async content(): Promise<string> {
		return this._tree_entry.content();
	}

	public static async fromPath(tree: Tree, path: string): Promise<Blob> {
		const entry = await tree.find(path);

		if(!(entry instanceof BlobTreeEntry)) {
			throw(createError(BlobError, 500, "Not a blob"));
		}

		return new Blob(entry, path);
	}
}