[ARVADOS-WORKBENCH2] updated: 1.1.4-449-g3402189
Git user
git at public.curoverse.com
Tue Jul 31 04:58:37 EDT 2018
Summary of changes:
src/models/keep-manifest.test.ts | 33 ++++++++++++++++++++++++
src/models/keep-manifest.ts | 55 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 88 insertions(+)
create mode 100644 src/models/keep-manifest.test.ts
create mode 100644 src/models/keep-manifest.ts
via 3402189ee23183fb7b655cd19815950c607b9679 (commit)
from 7eed338e122d5c5f16988acae10d304de15761bf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 3402189ee23183fb7b655cd19815950c607b9679
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Tue Jul 31 10:58:11 2018 +0200
Create model and parser for keep manifest
Feature #13855
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/models/keep-manifest.test.ts b/src/models/keep-manifest.test.ts
new file mode 100644
index 0000000..7de816c
--- /dev/null
+++ b/src/models/keep-manifest.test.ts
@@ -0,0 +1,33 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { parseKeepManifestText, parseKeepManifestStream } from "./keep-manifest";
+
+describe('parseKeepManifestText', () => {
+ it('should return correct number of streams', () => {
+ const manifestText = `. 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt
+ ./c d41d8cd98f00b204e9800998ecf8427e+0 0:0:d`;
+ const manifest = parseKeepManifestText(manifestText);
+ expect(manifest).toHaveLength(2);
+ });
+});
+
+describe('parseKeepManifestStream', () => {
+ const streamText = './c 930625b054ce894ac40596c3f5a0d947+33 0:0:a 0:0:b 0:33:output.txt';
+ const stream = parseKeepManifestStream(streamText);
+
+ it('should parse stream name', () => {
+ expect(stream.streamName).toBe('./c');
+ });
+ it('should parse stream locators', () => {
+ expect(stream.locators).toEqual(['930625b054ce894ac40596c3f5a0d947+33']);
+ });
+ it('should parse stream files', () => {
+ expect(stream.files).toEqual([
+ {fileName: 'a', position: '0', size: 0},
+ {fileName: 'b', position: '0', size: 0},
+ {fileName: 'output.txt', position: '0', size: 33},
+ ]);
+ });
+});
\ No newline at end of file
diff --git a/src/models/keep-manifest.ts b/src/models/keep-manifest.ts
new file mode 100644
index 0000000..0972e1e
--- /dev/null
+++ b/src/models/keep-manifest.ts
@@ -0,0 +1,55 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export type KeepManifest = KeepManifestStream[];
+
+export interface KeepManifestStream {
+ streamName: string;
+ locators: string[];
+ files: Array<KeepManifestStreamFile>;
+}
+
+export interface KeepManifestStreamFile {
+ fileName: 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 at _]*)*$/;
+
+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
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list