This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
98 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Debug from 'debug' | ||
import { BlobTree, Path, urlToPath } from './BlobTree' | ||
import { Member } from './Container' | ||
import { membersListAsQuadStream } from '../rdf/membersListAsResourceData' | ||
import { quadStreamFromBlob } from '../rdf/RdfLayer' | ||
import { rdfToResourceData } from '../rdf/rdfToResourceData' | ||
import { RdfType, objectToStream } from '../rdf/ResourceDataUtils' | ||
|
||
const debug = Debug('quad-and-blob-store') | ||
|
||
export class QuadAndBlobStore { | ||
storage: BlobTree | ||
constructor (storage: BlobTree) { | ||
this.storage = storage | ||
} | ||
getBlob (path: Path) { | ||
return this.storage.getBlob(path) | ||
} | ||
getContainer (path: Path) { | ||
return this.storage.getContainer(path) | ||
} | ||
async getQuadStream (url: URL, preferMinimalContainer?: boolean): Promise<any> { | ||
const path = urlToPath(url) | ||
if (path.isContainer) { | ||
const container = this.storage.getContainer(path) | ||
debug(container) | ||
let membersList: Array<Member> | ||
if (preferMinimalContainer) { | ||
membersList = [] | ||
} else { | ||
membersList = await container.getMembers() | ||
} | ||
debug(membersList) | ||
return membersListAsQuadStream(url, membersList) | ||
} else { | ||
const blob = this.storage.getBlob(path) | ||
const stream = await quadStreamFromBlob(blob) | ||
return stream | ||
} | ||
} | ||
async setQuadStream (url: URL, quadStream: any): Promise<void> { | ||
const path = urlToPath(url) | ||
if (path.isContainer) { | ||
throw new Error('cannot set QuadStream on Container') | ||
} else { | ||
const blob = this.storage.getBlob(path) | ||
const resourceData = rdfToResourceData(quadStream, RdfType.Turtle) | ||
return blob.setData(objectToStream(resourceData)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.