All files / src/utils tar-uploader.ts

100% Statements 12/12
100% Branches 0/0
100% Functions 1/1
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35  33x 33x 33x 33x     33x   33x           6x 6x                       6x 6x 6x   6x    
import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..'
import { prepareRequestHeaders } from './headers'
import { http } from './http'
import { TarStream } from './tar'
import { writeTar } from './tar-writer'
import { BatchId } from './typed-bytes'
 
const bzzEndpoint = 'bzz'
 
export async function uploadTar(
  requestOptions: BeeRequestOptions,
  collection: Collection,
  postageBatchId: BatchId,
  options?: CollectionUploadOptions,
) {
  const tarStream = new TarStream()
  const responsePromise = http<unknown>(requestOptions, {
    method: 'post',
    url: bzzEndpoint,
    data: tarStream.output,
    responseType: 'json',
    headers: {
      'content-type': 'application/x-tar',
      'swarm-collection': 'true',
      ...prepareRequestHeaders(postageBatchId, options),
    },
  })
 
  await writeTar(collection, tarStream)
  await tarStream.end()
  const response = await responsePromise
 
  return response
}