class RHostedFacetImpl extends FacetSupport implements RHostedFacet {

  @Override
  @TransactionalTouchMetadata
  public Content buildAndPutPackagesGz(final String basePath) throws IOException {
    checkNotNull(basePath);
    StorageTx tx = UnitOfWork.currentTx();
    RPackagesBuilder packagesBuilder = new RPackagesBuilder();
    Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE);
    StreamSupport.stream(archiveAssets.spliterator(), false) // packageInfoBuilder doesn't support multithreading
        .filter(asset -> basePath.equals(getBasePath(asset.name())))
        .forEach(packagesBuilder::append);
    byte[] packagesBytes = packagesBuilder.buildPackagesGz();
    StorageFacet storageFacet = getRepository().facet(StorageFacet.class);
    try (InputStream is = new ByteArrayInputStream(packagesBytes)) {
      TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS);
      return doPutPackagesGz(tx, basePath, tempPackagesGz);
    }
  }

}