aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/blob.ts
blob: e44a979e59d06cb0b96cc408d9a759ee3feb8489 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { TreeEntry as NodeGitTreeEntry } from "nodegit";
import { BlobError, createError } from "./error";

export class Blob {
	private _ng_tree_entry: NodeGitTreeEntry;

	constructor(entry: NodeGitTreeEntry) {
		this._ng_tree_entry = entry;
	}

	public async content(): Promise<string> {
		if(!this._ng_tree_entry.isBlob()) {
			throw(createError(BlobError, 500, "Not a blob"));
		}
		return this._ng_tree_entry.isBlob() ? (await this._ng_tree_entry.getBlob()).toString() : "";
	}
}