<commit_before>/* global FormData */
import { sendRequest, forEach } from 'substance'

export default class HttpStorageClient {
  constructor (apiUrl) {
    this.apiUrl = apiUrl
  }

  /*
    @returns a Promise for a raw archive, i.e. the data for a DocumentArchive.
  */
  read (archiveId, cb) {
    let url = this.apiUrl
    if (archiveId) {
      url = url + '/' + archiveId
    }
    return sendRequest({
      method: 'GET',
      url
    }).then(response => {
      cb(null, JSON.parse(response))
    }).catch(err => {
      cb(err)
    })
  }

  write (archiveId, data, cb) {
    let form = new FormData()
    forEach(data.resources, (record, filePath) => {
      if (record.encoding === 'blob') {
        // removing the blob from the record and submitting it as extra part
        form.append(record.id, record.data, filePath)
        delete record.data
      }
    })
    form.append('_archive', JSON.stringify(data))
    let url = this.apiUrl
    if (archiveId) {
      url = url + '/' + archiveId
    }
    return sendRequest({
      method: 'PUT',
      url,
      data: form
    }).then(() => {
      cb()
    }).catch(err => {
      cb(err)
    })
  }
}<commit_msg>Let HttpStorageClient pass through response.<commit_after>/* global FormData */
import { sendRequest, forEach } from 'substance'

export default class HttpStorageClient {
  constructor (apiUrl) {
    this.apiUrl = apiUrl
  }

  /*
    @returns a Promise for a raw archive, i.e. the data for a DocumentArchive.
  */
  read (archiveId, cb) {
    let url = this.apiUrl
    if (archiveId) {
      url = url + '/' + archiveId
    }
    return sendRequest({
      method: 'GET',
      url
    }).then(response => {
      cb(null, JSON.parse(response))
    }).catch(err => {
      cb(err)
    })
  }

  write (archiveId, data, cb) {
    let form = new FormData()
    forEach(data.resources, (record, filePath) => {
      if (record.encoding === 'blob') {
        // removing the blob from the record and submitting it as extra part
        form.append(record.id, record.data, filePath)
        delete record.data
      }
    })
    form.append('_archive', JSON.stringify(data))
    let url = this.apiUrl
    if (archiveId) {
      url = url + '/' + archiveId
    }
    return sendRequest({
      method: 'PUT',
      url,
      data: form
    }).then(response => {
      cb(response)
    }).catch(err => {
      cb(err)
    })
  }
}
{'fraction_non_alphanumeric': 0.13846153846153847, 'fraction_numerical': 0.0, 'mean_word_length': 2.1825396825396823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2825106', 'n_tokens_mistral': 770, 'n_tokens_neox': 758, 'n_words': 208}