1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { KeepManifestStream, KeepManifestStreamFile } from "../../models/keep-manifest";
8 * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
10 export const parseKeepManifestText = (text: string) =>
13 .filter(streamText => streamText.length > 0)
14 .map(parseKeepManifestStream);
17 * Documentation [http://doc.arvados.org/api/storage.html](http://doc.arvados.org/api/storage.html)
19 export const parseKeepManifestStream = (stream: string): KeepManifestStream => {
20 const tokens = stream.split(' ');
22 name: streamName(tokens),
23 locators: locators(tokens),
28 const FILE_LOCATOR_REGEXP = /^([0-9a-f]{32})\+([0-9]+)(\+[A-Z][-A-Za-z0-9@_]*)*$/;
30 const FILE_REGEXP = /([0-9]+):([0-9]+):(.*)/;
32 const streamName = (tokens: string[]) => tokens[0].slice(1);
34 const locators = (tokens: string[]) => tokens.filter(isFileLocator);
36 const files = (tokens: string[]) => tokens.filter(isFile).map(parseFile);
38 const isFileLocator = (token: string) => FILE_LOCATOR_REGEXP.test(token);
40 const isFile = (token: string) => FILE_REGEXP.test(token);
42 const parseFile = (token: string): KeepManifestStreamFile => {
43 const match = FILE_REGEXP.exec(token);
44 const [position, size, name] = match!.slice(1);
45 return { name, position, size: parseInt(size, 10) };