diff options
Diffstat (limited to 'packages/server/src/git/blob.ts')
-rw-r--r-- | packages/server/src/git/blob.ts | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/packages/server/src/git/blob.ts b/packages/server/src/git/blob.ts index e44a979..ef9f9ab 100644 --- a/packages/server/src/git/blob.ts +++ b/packages/server/src/git/blob.ts @@ -1,17 +1,29 @@ -import { TreeEntry as NodeGitTreeEntry } from "nodegit"; import { BlobError, createError } from "./error"; +import { Tree } from "./tree"; +import { BlobTreeEntry } from "./tree_entry"; export class Blob { - private _ng_tree_entry: NodeGitTreeEntry; + private _tree_entry: BlobTreeEntry; - constructor(entry: NodeGitTreeEntry) { - this._ng_tree_entry = entry; + public path; + + constructor(entry: BlobTreeEntry, path: string) { + this._tree_entry = entry; + + this.path = path; } public async content(): Promise<string> { - if(!this._ng_tree_entry.isBlob()) { + 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 this._ng_tree_entry.isBlob() ? (await this._ng_tree_entry.getBlob()).toString() : ""; + + return new Blob(entry, path); } }
\ No newline at end of file |