forked from microsoft/azure-devops-node-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilecontainer.ts
More file actions
52 lines (43 loc) · 1.78 KB
/
filecontainer.ts
File metadata and controls
52 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import * as fs from 'fs';
import * as path from 'path';
import * as stream from 'stream';
import * as cm from './common';
import * as vm from 'vso-node-api';
import * as ta from 'vso-node-api/FileContainerApi';
import * as ti from 'vso-node-api/interfaces/FileContainerInterfaces';
export async function run() {
try
{
let vsts: vm.WebApi = await cm.getWebApi();
let fileContainerApi = vsts.getFileContainerApi();
let containers = await fileContainerApi.getContainers(null, null);
if (containers.length > 0) {
let container = containers[0];
console.log("found container " + container.name);
let containerId = container.id;
let items = await fileContainerApi.getItems(containerId, null, null, null, null, null, null, false);
console.log("found " + items.length + " items");
let item = items.filter((item) => {
return item.itemType === ti.ContainerItemType.File;
})[0];
if (item) {
console.log("downloading " + item.path);
let restResponse = await fileContainerApi.getItem(containerId, null, item.path, item.path.substring(item.path.lastIndexOf('/') + 1));
let output = "";
await new Promise((resolve, reject) => {
restResponse.result.on('data', (chunk) => {
output += chunk;
});
restResponse.result.on('end', () => {
resolve(output);
});
});
console.log("downloaded " + item.path);
console.log(output);
}
}
}
catch (err) {
console.error('Error: ' + err.stack);
}
}