--- title: "Assembling Virtual Package Contents" order: 5 ---

Virtual packages are essentially references to other packages and resources, and before a virtual package can be consumed, it must first be "assembled" into a regular package.

Assembling a virtual package is essentially following pointers to resources and combining the contents of those resources. Once this is done, it's indistinguishable from a regular package and is therefore no longer considered "virtual". It's therefore a one-way process.

To assemble a virtual package, the following logic must be applied:

- The contents array is enumerated; each resource is assessed as follows:
  - If it's a file resource: the contents are downloaded, and verified (if a `hash` is specified), and written to the target virtual path. A directory is created if it doesn't exist, and a file is overwritten if it already exists.
  - If it's a package resource: the current package source is queried for the specified package (including `hash`). The contents are then extracted to the target virtual path, overwriting any existing files.
- The metaContents array is enumerated; each resource is assessed as follows:
  - If the virtualPath is upack.json or within the packages directory: the operation fails
  - If it's a file resource: the contents are downloaded, and verified (if a `hash` is specified), and written to the target virtual path. A directory is created if it doesn't exist, and a file is overwritten if it already exists.
  - If it's a package resource: the current package source is queried for the specified package (including `hash`). The contents are then extracted to the target virtual path, overwriting any existing files.
- If any error occurs during assembly, then the entire operation fails.