 # Local (client-only) document of importing files
 class ImportingFile extends Document
   # name: user's file name
-  # readProgress: progress of reading from file, in %
+  # preprocessingProgress: progress of reading from file, in %
   # uploadProgress: progress of uploading file, in %
   # status: current status or error message
   # finished: true when importing has finished

      return

    if result.verify
      verifyFile importingFilesArrayBuffer[document._id], result.publicationId, result.samples
    else
      uploadFile importingFilesArrayBuffer[document._id], result.publicationId


computeChecksum = (file, callback) ->
  hash = new Crypto.SHA256
    onProgress: (progress) ->
      #TODO: update progressbar
  hash.update file.content, (error, result) ->
    if error
      ImportingFile.documents.update file._id,

        errored: true
        status: "Invalid PDF file"

# Process next element from preprocessing queue
Deps.autorun ->
  document = ImportingFile.documents.findOne
    sha256:
      $exists: false
  ,
    fields:
      _id: 1
  return unless document

  ImportingFile.documents.update document._id,
    $set:
      status: "Preprocessing"

  reader = new FileReader()
  reader.onload = ->
    importingFiles[document._id].content = @result
    testPDF importingFiles[document._id], ->
      computeChecksum importingFiles[document._id], (error, result) ->
        if error
          ImportingFile.documents.update document._id,
            $set:
