1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export type KeepManifest = KeepManifestStream[];
7 export interface KeepManifestStream {
10 files: Array<KeepManifestStreamFile>;
13 export interface KeepManifestStreamFile {
20 * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
22 export const parseKeepManifestText = (text: string) =>
25 .filter(streamText => streamText.length > 0)
26 .map(parseKeepManifestStream);
29 * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
31 export const parseKeepManifestStream = (stream: string): KeepManifestStream => {
32 const tokens = stream.split(' ');
34 name: streamName(tokens),
35 locators: locators(tokens),
40 const FILE_LOCATOR_REGEXP = /^([0-9a-f]{32})\+([0-9]+)(\+[A-Z][-A-Za-z0-9@_]*)*$/;
42 const FILE_REGEXP = /([0-9]+):([0-9]+):(.*)/;
44 const streamName = (tokens: string[]) => tokens[0].slice(1);
46 const locators = (tokens: string[]) => tokens.filter(isFileLocator);
48 const files = (tokens: string[]) => tokens.filter(isFile).map(parseFile);
50 const isFileLocator = (token: string) => FILE_LOCATOR_REGEXP.test(token);
52 const isFile = (token: string) => FILE_REGEXP.test(token);
54 const parseFile = (token: string): KeepManifestStreamFile => {
55 const match = FILE_REGEXP.exec(token);
56 const [position, size, name] = match!.slice(1);
57 return { name, position, size: parseInt(size, 10) };