client/js/identify.js
function() {
            var self = this,
                identifier = new qq.Promise(),
                previewable = false,
                name = fileOrBlob.name === undefined ? "blob" : fileOrBlob.name;

            log(qq.format("Attempting to determine if {} can be rendered in this browser", name));

            log("First pass: check type attribute of blob object.");

            if (this.isPreviewableSync()) {
                log("Second pass: check for magic bytes in file header.");

                qq.readBlobToHex(fileOrBlob, 0, 4).then(function(hex) {
                    qq.each(self.PREVIEWABLE_MIME_TYPES, function(mime, bytes) {
                        if (isIdentifiable(bytes, hex)) {
                            // Safari is the only supported browser that can deal with TIFFs natively,
                            // so, if this is a TIFF and the UA isn't Safari, declare this file "non-previewable".
                            if (mime !== "image/tiff" || qq.supportedFeatures.tiffPreviews) {
                                previewable = true;
                                identifier.success(mime);
                            }

                            return false;
                        }
                    });

                    log(qq.format("'{}' is {} able to be rendered in this browser", name, previewable ? "" : "NOT"));

                    if (!previewable) {
                        identifier.failure();
                    }
                },
                function() {
                    log("Error reading file w/ name '" + name + "'.  Not able to be rendered in this browser.");
                    identifier.failure();
                });
            }
            else {
                identifier.failure();
            }

            return identifier;
        }
function() {
            var self = this,
                identifier = new qq.Promise(),
                previewable = false,
                name = fileOrBlob.name === undefined ? "blob" : fileOrBlob.name;

            log(qq.format("Attempting to determine if {} can be rendered in this browser", name));

            log("First pass: check type attribute of blob object.");

            if (this.isPreviewableSync()) {
                log("Second pass: check for magic bytes in file header.");

                qq.readBlobToHex(fileOrBlob, 0, 4).then(function(hex) {
                    qq.each(self.PREVIEWABLE_MIME_TYPES, function(mime, bytes) {
                        if (isIdentifiable(bytes, hex)) {
                            // Safari is the only supported browser that can deal with TIFFs natively,
                            // so, if this is a TIFF and the UA isn't Safari, declare this file "non-previewable".
                            if (mime !== "image/tiff" || qq.supportedFeatures.tiffPreviews) {
                                previewable = true;
                                identifier.success(mime);
                            }

                            return false;
                        }
                    });

                    log(qq.format("'{}' is {} able to be rendered in this browser", name, previewable ? "" : "NOT"));

                    if (!previewable) {
                        identifier.failure();
                    }
                },
                function() {
                    log("Error reading file w/ name '" + name + "'.  Not able to be rendered in this browser.");
                    identifier.failure();
                });
            }
            else {
                identifier.failure();
            }

            return identifier;
        }
function ( ) { var self = this , identifier = new qq . Promise ( ) , previewable = false , name = fileOrBlob . name === undefined ? "blob" : fileOrBlob . name ; log ( qq . format ( "Attempting to determine if {} can be rendered in this browser" , name ) ) ; log ( "First pass: check type attribute of blob object." ) ; if ( this . isPreviewableSync ( ) ) { log ( "Second pass: check for magic bytes in file header." ) ; qq . readBlobToHex ( fileOrBlob , 0 , 4 ) . then ( function ( hex ) { qq . each ( self . PREVIEWABLE_MIME_TYPES , function ( mime , bytes ) { if ( isIdentifiable ( bytes , hex ) ) { // Safari is the only supported browser that can deal with TIFFs natively, // so, if this is a TIFF and the UA isn't Safari, declare this file "non-previewable". if ( mime !== "image/tiff" || qq . supportedFeatures . tiffPreviews ) { previewable = true ; identifier . success ( mime ) ; } return false ; } } ) ; log ( qq . format ( "'{}' is {} able to be rendered in this browser" , name , previewable ? "" : "NOT" ) ) ; if ( ! previewable ) { identifier . failure ( ) ; } } , function ( ) { log ( "Error reading file w/ name '" + name + "'.  Not able to be rendered in this browser." ) ; identifier . failure ( ) ; } ) ; } else { identifier . failure ( ) ; } return identifier ; }
Determines if a Blob can be displayed natively in the current browser.  This is done by reading magic
bytes in the beginning of the file, so this is an asynchronous operation.  Before we attempt to read the
file, we will examine the blob's type attribute to save CPU cycles.

@returns {qq.Promise} Promise that is fulfilled when identification is complete.
If successful, the MIME string is passed to the success handler.
Determines if a Blob can be displayed natively in the current browser . This is done by reading magic bytes in the beginning of the file so this is an asynchronous operation . Before we attempt to read the file we will examine the blob s type attribute to save CPU cycles .