     @returns {Boolean} - True if stream is fulfilled, false if queue is in progress
     ###
     end: (callback) ->
-      if not @aborted and not @stream._writableState.ended
+      if not @aborted and not @ended
         if @writtenChunks is @maxLength
-          @stream.end callback
+          self = @
+          fs.close @fd, -> bound ->
+            self.ended = true
+            callback and callback()
+            return
           return true
         else
           self = @

  @summary writableStream wrapper class, makes sure chunks is written in given order. Implementation of queue stream.
  ###
  class writeStream
    constructor: (@path, @maxLength, @file) ->
      if not @path or not _.isString @path
        return
      self           = @
      fs.ensureFileSync @path
      @stream        = fs.createWriteStream @path, {flags: 'a', mode: self.permissions, highWaterMark: 0}
      @drained       = true
      @aborted       = false
      @writtenChunks = 0

      @stream.on 'drain', -> bound ->
        ++self.writtenChunks
        self.drained = true
        return

      @stream.on 'error', (error) -> bound ->
        console.error "[FilesCollection] [writeStream] [ERROR:]", error
        self.abort()
        return

    ###
    @memberOf writeStream

                  {result, opts}  = self._prepareUpload _.extend(opts, _continueUpload), user.userId, 'HTTP'

                  if opts.eof
                    self._handleUpload result, opts, ->
                      response.writeHead 200
                      result.file.meta = fixJSONStringify result.file.meta if result?.file?.meta
                      response.end JSON.stringify result
                      return
                    return
                  else
                    self.emit '_handleUpload', result, opts, NOOP

