Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
minor optimization
  • Loading branch information
Amit Kapadia committed Oct 30, 2013
1 parent d3b0de8 commit 8ea481a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
17 changes: 4 additions & 13 deletions lib/fits.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "fits",
"version": "0.6.0",
"version": "0.6.1",
"author": "Amit Kapadia <amit@zooniverse.org>",
"description": "Library for reading the FITS astronomical file format",
"repository": {
Expand Down
14 changes: 5 additions & 9 deletions src/fits.coffee
Expand Up @@ -68,7 +68,7 @@ class Parser extends Base
if typeof(@arg) is 'string'

# Define function at runtime for getting next block
@readNextBlock = @_readBlockFromBuffer
@readNextBlock = @readBlock

# Get the remote file as an arraybuffer
xhr = new XMLHttpRequest()
Expand Down Expand Up @@ -99,9 +99,6 @@ class Parser extends Base
# Store the file byte length
@length = @arg.size

# Define function at runtime for getting next block
@readNextBlock = @_readBlockFromFile

# Get the local file as an arraybuffer
@readFromFile()

Expand All @@ -123,6 +120,9 @@ class Parser extends Base
# Initialize a new FileReader
@reader = new FileReader()

# Define function at runtime for getting next block
@readNextBlock = @reader.readAsArrayBuffer

# Set reader handler
@reader.onloadend = (e) =>
@readBlock(e.target.result)
Expand Down Expand Up @@ -220,10 +220,6 @@ class Parser extends Base
@readNextBlock(block)
return

# Use one of these depending on the initialization parameter (File or ArrayBuffer)
_readBlockFromBuffer: (block) -> @readBlock(block)
_readBlockFromFile: (block) -> @reader.readAsArrayBuffer(block)

# Create the appropriate data unit based on info from header
createDataUnit: (header, blob) ->
type = header.getDataType()
Expand Down Expand Up @@ -265,5 +261,5 @@ class FITS extends Base
getDataUnit: (index) -> return @getHDU(index).data


FITS.version = '0.6.0'
FITS.version = '0.6.1'
@astro.FITS = FITS
2 changes: 1 addition & 1 deletion src/image.coffee
Expand Up @@ -129,7 +129,7 @@ class Image extends DataUnit
blobGetFrame = new Blob([fn2], {type: mime})

# Create URLs to onmessage and _getFrame scripts
URL = window.URL or window.webkitURL # to appease Safari
# URL = URL or webkitURL # to appease Safari
urlOnMessage = URL.createObjectURL(blobOnMessage)
urlGetFrame = URL.createObjectURL(blobGetFrame)

Expand Down
14 changes: 14 additions & 0 deletions test/specs/fits.coffee
Expand Up @@ -47,4 +47,18 @@ describe "FITS", ->
expect(fits.hdus.length).toEqual(2)
expect(fits.getDataUnit(0).constructor.name).toBe("Image")
expect(fits.getDataUnit(1).constructor.name).toBe("Table")

it 'can open a gzipped FITS file quickly', ->
ready = false

path = "http://radio.galaxyzoo.org.s3.amazonaws.com/beta/subjects/raw/S1029.fits.gz"
new astro.FITS(path, (f) ->
ready = true
)

waitsFor ->
return ready

runs ->
console.log "READY"

0 comments on commit 8ea481a

Please sign in to comment.