class NpmFacetImpl extends FacetSupport implements NpmFacet {

  @Nullable
  @Override
  public Asset putTarball(final String packageId,
                          final String tarballName,
                          final AssetBlob assetBlob,
                          @Nullable final AttributesMap contentAttributes) throws IOException
  {
    final Repository repository = getRepository();
    final StorageTx tx = UnitOfWork.currentTx();
    final Bucket bucket = tx.findBucket(repository);
    NpmPackageId npmPackageId = NpmPackageId.parse(packageId);
    Asset asset = NpmFacetUtils.findTarballAsset(tx, bucket, npmPackageId, tarballName);

    if (asset == null) {
      String version = extractVersion(tarballName);
      Component tarballComponent = getOrCreateTarballComponent(tx, repository, npmPackageId, version);
      asset = tx.firstAsset(tarballComponent);

      if (asset == null) {
        asset = tx.createAsset(bucket, tarballComponent).name(tarballAssetName(npmPackageId, tarballName));
      }
    }

    maybeExtractFormatAttributes(tx, packageId, asset, assetBlob);
    saveAsset(tx, asset, assetBlob, TARBALL, contentAttributes);

    return asset;
  }

  @Inject public  NpmFacetImpl(final NpmPackageParser npmPackageParser);

}