X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/219d452e647c01754bf71b91086b15cc9f00027a..d714e4787834d3440f9d73aca940cc2544e8f174:/src/services/collection-files-service/collection-manifest-parser.ts diff --git a/src/services/collection-files-service/collection-manifest-parser.ts b/src/services/collection-files-service/collection-manifest-parser.ts index df334d49..d564f33e 100644 --- a/src/services/collection-files-service/collection-manifest-parser.ts +++ b/src/services/collection-files-service/collection-manifest-parser.ts @@ -2,12 +2,12 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { KeepManifestStream, KeepManifestStreamFile } from "../../models/keep-manifest"; +import { KeepManifestStream, KeepManifestStreamFile, KeepManifest } from "~/models/keep-manifest"; /** * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html) */ -export const parseKeepManifestText = (text: string) => +export const parseKeepManifestText: (text: string) => KeepManifestStream[] = (text: string) => text .split(/\n/) .filter(streamText => streamText.length > 0) @@ -25,6 +25,12 @@ export const parseKeepManifestStream = (stream: string): KeepManifestStream => { }; }; +export const stringifyKeepManifest = (manifest: KeepManifest) => + manifest.map(stringifyKeepManifestStream).join(''); + +export const stringifyKeepManifestStream = (stream: KeepManifestStream) => + `.${stream.name} ${stream.locators.join(' ')} ${stream.files.map(stringifyFile).join(' ')}\n`; + const FILE_LOCATOR_REGEXP = /^([0-9a-f]{32})\+([0-9]+)(\+[A-Z][-A-Za-z0-9@_]*)*$/; const FILE_REGEXP = /([0-9]+):([0-9]+):(.*)/; @@ -43,4 +49,7 @@ const parseFile = (token: string): KeepManifestStreamFile => { const match = FILE_REGEXP.exec(token); const [position, size, name] = match!.slice(1); return { name, position, size: parseInt(size, 10) }; -}; \ No newline at end of file +}; + +const stringifyFile = (file: KeepManifestStreamFile) => + `${file.position}:${file.size}:${file.name}`;