       message = oEvent.data.message
       self._handler[message] data
 
-  sendFile: (params) ->
-    @worker.postMessage message: 'file', file: params.file, chunkSize: Crypto.chunkSize
+  _nextChunk: () ->
+    console.log "Received chunk ack"
+    @_busy = false
+    @_flush()
 
-  sendChunk: (params) ->
-    @worker.postMessage message: 'chunk', chunk: params.chunk, chunkNumber: params.chunkNumber
+  _flush: () ->
+    console.log "Flushing"
+    if not @_busy and @_buffer.length > 0
+      chunk = @_buffer.shift()
+      @_busy = true
+      @worker.postMessage chunk
 
-  finalize: (params) ->
-    @worker.postMessage message: 'finalize'
+  sendChunk: (chunk) ->
+    console.log "Adding chunk to buffer"
+    chunk.message = 'chunk'
+    @_buffer.push chunk
+    @_flush()
+
+  finalize: () ->
+    console.log "Adding final chunk to buffer"
+    @_buffer.push
+      message: 'finalize'
+    @_flush()
 
 class WorkerFallback extends BaseWorker
   constructor: (params) ->

  constructor: (params) ->
    self = @
    @_onProgress = ->
    @_onDone = ->
  
    @_handler =
      progress: (data) ->
        self._onProgress data
      done: (data) ->
        self._onDone data.sha256


        @worker = new WorkerFallback

    update: (params) ->
      console.log typeof params.data
      if params.onProgress?
        @worker.setOnProgress(params.onProgress)
      @_chunks = true
      console.log "Crypto sending chunk to worker"
      @worker.sendChunk
        chunk: params.data
        chunkNumber: @_chunkNumber++
