Skip to content

Commit 2c63329

Browse files
committed
Add containerExportStream() and containerCopyStream()
1 parent 5dfbf6f commit 2c63329

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/Client.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,29 @@ public function containerChanges($container)
152152
* @param string $container container ID
153153
* @return Promise Promise<string> tar stream
154154
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#export-a-container
155+
* @see self::containerExportStream()
155156
*/
156157
public function containerExport($container)
157158
{
158159
return $this->browser->get($this->url('/containers/%s/export', $container))->then(array($this->parser, 'expectPlain'));
159160
}
160161

162+
/**
163+
* Export the contents of container id
164+
*
165+
* The resulting stream is a well-behaving readable stream that will emit
166+
* the normal stream events.
167+
*
168+
* @param string $container container ID
169+
* @return ReadableStreamInterface tar stream
170+
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#export-a-container
171+
* @see self::containerExport()
172+
*/
173+
public function containerExportStream($container)
174+
{
175+
return $this->streamingParser->parsePlainStream($this->browser->get($this->url('/containers/%s/export', $container)));
176+
}
177+
161178
/**
162179
* Resize the TTY of container id
163180
*
@@ -280,12 +297,31 @@ public function containerRemove($container, $v = false, $force = false)
280297
* @param string $container container ID
281298
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
282299
* @return Promise Promise<string> tar stream
300+
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
301+
* @see self::containerCopyStream()
283302
*/
284303
public function containerCopy($container, $config)
285304
{
286305
return $this->postJson($this->url('/containers/%s/copy', $container), $config)->then(array($this->parser, 'expectPlain'));
287306
}
288307

308+
/**
309+
* Copy files or folders of container id
310+
*
311+
* The resulting stream is a well-behaving readable stream that will emit
312+
* the normal stream events.
313+
*
314+
* @param string $container container ID
315+
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
316+
* @return ReadableStreamInterface tar stream
317+
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
318+
* @see self::containerCopy()
319+
*/
320+
public function containerCopyStream($container, $config)
321+
{
322+
return $this->streamingParser->parsePlainStream($this->postJson($this->url('/containers/%s/copy', $container), $config));
323+
}
324+
289325
/**
290326
* List images
291327
*

tests/ClientTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public function testContainerExport()
8686
$this->expectPromiseResolveWith($data, $this->client->containerExport(123));
8787
}
8888

89+
public function testContainerExportStream()
90+
{
91+
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
92+
93+
$this->expectRequest('get', '/containers/123/export', $this->createResponse(''));
94+
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
95+
96+
$this->assertSame($stream, $this->client->containerExportStream(123));
97+
}
98+
8999
public function testContainerWait()
90100
{
91101
$json = array();
@@ -168,12 +178,23 @@ public function testContainerResize()
168178
public function testContainerCopy()
169179
{
170180
$data = 'tar stream';
171-
$config = array('Resource' => 'file.txt');
172181
$this->expectRequestFlow('post', '/containers/123/copy', $this->createResponse($data), 'expectPlain');
173182

183+
$config = array('Resource' => 'file.txt');
174184
$this->expectPromiseResolveWith($data, $this->client->containerCopy('123', $config));
175185
}
176186

187+
public function testContainerCopyStream()
188+
{
189+
$stream = $this->getMock('React\Stream\ReadableStreamInterface');
190+
191+
$this->expectRequest('post', '/containers/123/copy', $this->createResponse(''));
192+
$this->streamingParser->expects($this->once())->method('parsePlainStream')->will($this->returnValue($stream));
193+
194+
$config = array('Resource' => 'file.txt');
195+
$this->assertSame($stream, $this->client->containerCopyStream('123', $config));
196+
}
197+
177198
public function testImageList()
178199
{
179200
$json = array();

0 commit comments

Comments
 (0)