mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Added progress stats to reading files
This commit is contained in:
@@ -193,6 +193,18 @@ describe "Project", ->
|
||||
project.openAsync("bar://baz").then (item) ->
|
||||
expect(item).toEqual { bar: "bar://baz" }
|
||||
|
||||
it "returns number of read bytes as progress indicator", ->
|
||||
filePath = project.resolve 'a'
|
||||
totalBytes = 0
|
||||
promise = project.openAsync(filePath)
|
||||
promise.progress (bytesRead) -> totalBytes = bytesRead
|
||||
|
||||
waitsForPromise ->
|
||||
promise
|
||||
|
||||
runs ->
|
||||
expect(totalBytes).toBe fs.statSync(filePath).size
|
||||
|
||||
describe ".bufferForPath(path)", ->
|
||||
describe "when opening a previously opened path", ->
|
||||
it "does not create a new buffer", ->
|
||||
|
||||
@@ -62,7 +62,22 @@ class File
|
||||
if not @exists()
|
||||
promise = Q(null)
|
||||
else if not @cachedContents? or flushCache
|
||||
promise = Q.nfcall fsUtils.readFile, @getPath(), 'utf8'
|
||||
deferred = Q.defer()
|
||||
promise = deferred.promise
|
||||
|
||||
content = []
|
||||
size = 0
|
||||
readStream = fsUtils.createReadStream @getPath(), encoding: 'utf8'
|
||||
readStream.on 'data', (chunk) ->
|
||||
content.push(chunk)
|
||||
size += chunk.length
|
||||
deferred.notify(size)
|
||||
|
||||
readStream.on 'end', ->
|
||||
deferred.resolve(content.join())
|
||||
|
||||
readStream.on 'error', (error) ->
|
||||
deferred.reject(error ? "REPLACE THIS ERROR MESSAGE, fs.readStream doesn't output an error message!")
|
||||
else
|
||||
promise = Q(@cachedContents)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user