X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3402189ee23183fb7b655cd19815950c607b9679..fd49462a5a09e107b7bb5c0ef8635db328b399b8:/src/models/keep-manifest.ts diff --git a/src/models/keep-manifest.ts b/src/models/keep-manifest.ts index 0972e1e6..6dc64450 100644 --- a/src/models/keep-manifest.ts +++ b/src/models/keep-manifest.ts @@ -5,51 +5,13 @@ export type KeepManifest = KeepManifestStream[]; export interface KeepManifestStream { - streamName: string; + name: string; locators: string[]; files: Array; } export interface KeepManifestStreamFile { - fileName: string; + name: string; position: string; size: number; } - -/** - * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html) - */ -export const parseKeepManifestText = (text: string) => - text.split(/\n/).map(parseKeepManifestStream); - -/** - * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html) - */ -export const parseKeepManifestStream = (stream: string): KeepManifestStream => { - const tokens = stream.split(' '); - return { - streamName: streamName(tokens), - locators: locators(tokens), - files: files(tokens) - }; -}; - -const FILE_LOCATOR_REGEXP = /^([0-9a-f]{32})\+([0-9]+)(\+[A-Z][-A-Za-z0-9@_]*)*$/; - -const FILE_REGEXP = /([0-9]+):([0-9]+):(.*)/; - -const streamName = (tokens: string[]) => tokens[0]; - -const locators = (tokens: string[]) => tokens.filter(isFileLocator); - -const files = (tokens: string[]) => tokens.filter(isFile).map(parseFile); - -const isFileLocator = (token: string) => FILE_LOCATOR_REGEXP.test(token); - -const isFile = (token: string) => FILE_REGEXP.test(token); - -const parseFile = (token: string): KeepManifestStreamFile => { - const match = FILE_REGEXP.exec(token); - const [position, size, fileName] = match!.slice(1); - return { fileName, position, size: parseInt(size, 10) }; -}; \ No newline at end of file