Skip to content

Commit 24f68ef

Browse files
committed
returns a writeable stream
1 parent 3ba9ddf commit 24f68ef

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

lib/dotetch/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ import { ExtendedManifests, Image } from './interface-manifest';
44
import { computeDockerLayers, streamDockerLayers, Layer } from './layers';
55
import { AxiosBasicCredentials } from "axios";
66

7-
type Version1 = "1.0" // add valid 1.x versions for MannifestV1 here
8-
type TypeV1 = "stream" // add valid types here
9-
107
interface ManifestV1 {
11-
version: Version1,
8+
version: "1.0",
129
baseImage?: {
13-
type: TypeV1;
10+
type: "stream";
1411
location: string;
1512
},
1613
inject?: [{
17-
type: TypeV1;
14+
type: "stream";
1815
location: string;
1916
targetPartition: number;
2017
}]
@@ -32,7 +29,6 @@ interface ManifestV1 {
3229
* 3. /inject/_partitions_/_foldersOrFilesToInject_ - injectables assets
3330
*/
3431

35-
3632
/**
3733
* PromisePacker
3834
* Promisify tar-stream.pack.entry ( https://www.npmjs.com/package/tar-stream )
@@ -63,9 +59,8 @@ const promisePacker =
6359
* @param manifest A dotEtch manifest
6460
* @returns tar-stream pack writable stream
6561
*/
66-
const prepareEtchStream = async (outputStream: NodeJS.WritableStream, manifest: ManifestV1): Promise<Pack> => {
62+
const prepareEtchStream = async (manifest: ManifestV1): Promise<Pack> => {
6763
const packStream = pack();
68-
packStream.pipe(outputStream);
6964

7065
// stream manifest
7166
const packer = promisePacker(packStream);

lib/dotetch/readme.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ Entry is `index.ts`
66

77
You're responsible for managing the lifecycle :
88

9-
1. call `prepareEtchStream` passing a writable stream (i.e. response to an http query), it will return a "PackStream" [which is a `pack` from tar-stream](https://github.com/mafintosh/tar-stream) and a manifest.
10-
2. call `startEtchStream` with those mandatory parameters :
9+
1. call `prepareEtchStream` with a manifest, it will return a "PackStream" [which is a `pack` from tar-stream](https://github.com/mafintosh/tar-stream).
10+
2. pipe the stream from 1. to an output `packStream.pipe(outputStream)` (output stream can be a file, a http response, ...)
11+
3. call `startEtchStream` with those mandatory parameters :
1112
- `packStream` (from previous step)
1213
- `baseImageStream` readable stream for the baseimage (either .img or a .img in a zip),
1314
- `baseImageSize` size of the baseImage in bytes,
1415
- `baseImageName` name of the baseImage file
1516

16-
3. wait for 2 to finish streaming the baseImage
17-
4. stream any number of file you want to inject using `PackStream` from step 1. Those files will be injected on top of the base image's by etcher at flash. You need to place them at the right place in the stream which is :
17+
4. wait for 2 to finish streaming the baseImage
18+
5. stream any number of file you want to inject using `PackStream` from step 1. Those files will be injected on top of the base image's by etcher at flash. You need to place them at the right place in the stream which is :
1819
`/inject/**partitionNumber**/path/to/file`. At flash time, `/inject/` will be dropped and `**partitionNumber**` will determine in which partition your files will be written `/path/to/file` is relative to the root of that partition. You can use any function availble on a `tar-stream pack` (writing files, symlinks, hardlinks, folders, setting permissions, etc. ). Note that you don't need to spcecifically create folders before putting files in it, they will be created if they don't exist.
1920

2021
Note that there's a few helper function in the lib:
2122
- `promisePacker` which wraps `tar-stream.pack` in a promise so you can `await` it
2223
- `streamFiles` which lets you easily inject arbitrary files
2324
- `streamDockerAssets` which takes a list of docker images (and credentials) and stream them (cf section about docker)
2425

25-
5. call `closeEtchStream` to properly close the tar stream.
26+
6. call `closeEtchStream` to properly close the tar stream.
2627

2728
## Usage with Docker / Balena
2829
This whole .etch feature has been developed by [balena](https://www.balena.io) in order to permet automatic preloading of balenaOS images with a user application (made of multiple docker images).

0 commit comments

Comments
 (0)