@@ -557,7 +557,7 @@ public function containerRemove($container, $v = false, $force = false)
557557 }
558558
559559 /**
560- * Copy files or folders of container id
560+ * [deprecated] Copy files or folders of container id
561561 *
562562 * This resolves with a string in the TAR file format containing all files
563563 * specified in the given $path.
@@ -575,6 +575,8 @@ public function containerRemove($container, $v = false, $force = false)
575575 * @return PromiseInterface Promise<string> tar stream
576576 * @link https://docs.docker.com/engine/api/v1.22/#copy-files-or-folders-from-a-container
577577 * @link https://github.com/clue/reactphp-tar
578+ * @deprecated 0.3.0 Deprecated in Docker Engine API v1.20 (Docker v1.8) and removed in Docker Engine API v1.24 (Docker v1.12), use `containerArchive()` instead
579+ * @see self::containerArchive()
578580 * @see self::containerCopyStream()
579581 */
580582 public function containerCopy ($ container , $ path )
@@ -593,7 +595,7 @@ public function containerCopy($container, $path)
593595 }
594596
595597 /**
596- * Copy files or folders of container id
598+ * [Deprecated] Copy files or folders of container id
597599 *
598600 * This returns a stream in the TAR file format containing all files
599601 * specified in the given $path.
@@ -613,6 +615,8 @@ public function containerCopy($container, $path)
613615 * @return ReadableStreamInterface tar stream
614616 * @link https://docs.docker.com/engine/api/v1.22/#copy-files-or-folders-from-a-container
615617 * @link https://github.com/clue/reactphp-tar
618+ * @deprecated 0.3.0 Deprecated in Docker Engine API v1.20 (Docker v1.8) and removed in Docker Engine API v1.24 (Docker v1.12), use `containerArchiveStream()` instead
619+ * @see self::containerArchiveStream()
616620 * @see self::containerCopy()
617621 */
618622 public function containerCopyStream ($ container , $ path )
@@ -635,6 +639,80 @@ public function containerCopyStream($container, $path)
635639 );
636640 }
637641
642+ /**
643+ * Get a tar archive of a resource in the filesystem of container id.
644+ *
645+ * This resolves with a string in the TAR file format containing all files
646+ * specified in the given $path.
647+ *
648+ * Keep in mind that this means the whole string has to be kept in memory.
649+ * For bigger containers it's usually a better idea to use a streaming approach,
650+ * see containerArchiveStream() for more details.
651+ *
652+ * Accessing individual files in the TAR file format string is out of scope
653+ * for this library. Several libraries are available, one that is known to
654+ * work is clue/reactphp-tar (see links).
655+ *
656+ * @param string $container container ID
657+ * @param string $resource path to file or directory to archive
658+ * @return PromiseInterface Promise<string> tar stream
659+ * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerArchive
660+ * @link https://github.com/clue/reactphp-tar
661+ * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8), use deprecated `containerCopy()` on legacy versions
662+ * @see self::containerArchiveStream()
663+ */
664+ public function containerArchive ($ container , $ path )
665+ {
666+ return $ this ->browser ->get (
667+ $ this ->uri ->expand (
668+ '/containers/{container}/archive{?path} ' ,
669+ array (
670+ 'container ' => $ container ,
671+ 'path ' => $ path
672+ )
673+ )
674+ )->then (array ($ this ->parser , 'expectPlain ' ));
675+ }
676+
677+ /**
678+ * Get a tar archive of a resource in the filesystem of container id.
679+ *
680+ * This returns a stream in the TAR file format containing all files
681+ * specified in the given $path.
682+ *
683+ * This works for (any number of) files of arbitrary sizes as only small chunks have to
684+ * be kept in memory.
685+ *
686+ * Accessing individual files in the TAR file format stream is out of scope
687+ * for this library. Several libraries are available, one that is known to
688+ * work is clue/reactphp-tar (see links).
689+ *
690+ * The resulting stream is a well-behaving readable stream that will emit
691+ * the normal stream events.
692+ *
693+ * @param string $container container ID
694+ * @param string $path path to file or directory to archive
695+ * @return ReadableStreamInterface tar stream
696+ * @link https://docs.docker.com/engine/api/v1.40/#operation/ContainerArchive
697+ * @link https://github.com/clue/reactphp-tar
698+ * @since 0.3.0 Available as of Docker Engine API v1.20 (Docker v1.8), use deprecated `containerCopyStream()` on legacy versions
699+ * @see self::containerArchive()
700+ */
701+ public function containerArchiveStream ($ container , $ path )
702+ {
703+ return $ this ->streamingParser ->parsePlainStream (
704+ $ this ->browser ->withOptions (array ('streaming ' => true ))->get (
705+ $ this ->uri ->expand (
706+ '/containers/{container}/archive{?path} ' ,
707+ array (
708+ 'container ' => $ container ,
709+ 'path ' => $ path
710+ )
711+ )
712+ )
713+ );
714+ }
715+
638716 /**
639717 * List images
640718 *
0 commit comments