Permalink
Browse files

Using the HTML5 File API rather than binaryajax.js

  • Loading branch information...
1 parent 2c68eee commit 4f5aa268b397b13ab54c95afce4db73dda93e922 @jory committed Dec 19, 2011
Showing with 146 additions and 389 deletions.
  1. +19 −19 MIT-LICENSE.txt
  2. 0 README
  3. +0 −278 js/binaryajax.js
  4. +109 −83 js/ttyplayer.js
  5. +18 −9 ttyplayer.html
View
38 MIT-LICENSE.txt 100644 → 100755
@@ -1,19 +1,19 @@
-Copyright (C) 2011 by Jory Graham
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+Copyright (C) 2011 by Jory Graham
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
0 README 100644 → 100755
No changes.
View
@@ -1,278 +0,0 @@
-
-/*
- * Binary Ajax 0.1.10
- * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/
- * Licensed under the MPL License [http://www.nihilogic.dk/licenses/mpl-license.txt]
- */
-
-
-var BinaryFile = function(strData, iDataOffset, iDataLength) {
- var data = strData;
- var dataOffset = iDataOffset || 0;
- var dataLength = 0;
-
- this.getRawData = function() {
- return data;
- }
-
- if (typeof strData == "string") {
- dataLength = iDataLength || data.length;
-
- this.getByteAt = function(iOffset) {
- return data.charCodeAt(iOffset + dataOffset) & 0xFF;
- }
-
- this.getBytesAt = function(iOffset, iLength) {
- var aBytes = [];
-
- for (var i = 0; i < iLength; i++) {
- aBytes[i] = data.charCodeAt((iOffset + i) + dataOffset) & 0xFF
- };
-
- return aBytes;
- }
- } else if (typeof strData == "unknown") {
- dataLength = iDataLength || IEBinary_getLength(data);
-
- this.getByteAt = function(iOffset) {
- return IEBinary_getByteAt(data, iOffset + dataOffset);
- }
-
- this.getBytesAt = function(iOffset, iLength) {
- return new VBArray(IEBinary_getBytesAt(data, iOffset + dataOffset, iLength)).toArray();
- }
- }
-
- this.getLength = function() {
- return dataLength;
- }
-
- this.getSByteAt = function(iOffset) {
- var iByte = this.getByteAt(iOffset);
- if (iByte > 127)
- return iByte - 256;
- else
- return iByte;
- }
-
- this.getShortAt = function(iOffset, bBigEndian) {
- var iShort = bBigEndian ?
- (this.getByteAt(iOffset) << 8) + this.getByteAt(iOffset + 1)
- : (this.getByteAt(iOffset + 1) << 8) + this.getByteAt(iOffset)
- if (iShort < 0) iShort += 65536;
- return iShort;
- }
- this.getSShortAt = function(iOffset, bBigEndian) {
- var iUShort = this.getShortAt(iOffset, bBigEndian);
- if (iUShort > 32767)
- return iUShort - 65536;
- else
- return iUShort;
- }
- this.getLongAt = function(iOffset, bBigEndian) {
- var iByte1 = this.getByteAt(iOffset),
- iByte2 = this.getByteAt(iOffset + 1),
- iByte3 = this.getByteAt(iOffset + 2),
- iByte4 = this.getByteAt(iOffset + 3);
-
- var iLong = bBigEndian ?
- (((((iByte1 << 8) + iByte2) << 8) + iByte3) << 8) + iByte4
- : (((((iByte4 << 8) + iByte3) << 8) + iByte2) << 8) + iByte1;
- if (iLong < 0) iLong += 4294967296;
- return iLong;
- }
- this.getSLongAt = function(iOffset, bBigEndian) {
- var iULong = this.getLongAt(iOffset, bBigEndian);
- if (iULong > 2147483647)
- return iULong - 4294967296;
- else
- return iULong;
- }
-
- this.getStringAt = function(iOffset, iLength) {
- var aStr = [];
-
- var aBytes = this.getBytesAt(iOffset, iLength);
- for (var j=0; j < iLength; j++) {
- aStr[j] = String.fromCharCode(aBytes[j]);
- }
- return aStr.join("");
- }
-
- this.getCharAt = function(iOffset) {
- return String.fromCharCode(this.getByteAt(iOffset));
- }
- this.toBase64 = function() {
- return window.btoa(data);
- }
- this.fromBase64 = function(strBase64) {
- data = window.atob(strBase64);
- }
-}
-
-
-var BinaryAjax = (function() {
-
- function createRequest() {
- var oHTTP = null;
- if (window.ActiveXObject) {
- oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
- } else if (window.XMLHttpRequest) {
- oHTTP = new XMLHttpRequest();
- }
- return oHTTP;
- }
-
- function getHead(strURL, fncCallback, fncError) {
- var oHTTP = createRequest();
- if (oHTTP) {
- if (fncCallback) {
- if (typeof(oHTTP.onload) != "undefined") {
- oHTTP.onload = function() {
- if (oHTTP.status == "200") {
- fncCallback(this);
- } else {
- if (fncError) fncError();
- }
- oHTTP = null;
- };
- } else {
- oHTTP.onreadystatechange = function() {
- if (oHTTP.readyState == 4) {
- if (oHTTP.status == "200") {
- fncCallback(this);
- } else {
- if (fncError) fncError();
- }
- oHTTP = null;
- }
- };
- }
- }
- oHTTP.open("HEAD", strURL, true);
- oHTTP.send(null);
- } else {
- if (fncError) fncError();
- }
- }
-
- function sendRequest(strURL, fncCallback, fncError, aRange, bAcceptRanges, iFileSize) {
- var oHTTP = createRequest();
- if (oHTTP) {
-
- var iDataOffset = 0;
- if (aRange && !bAcceptRanges) {
- iDataOffset = aRange[0];
- }
- var iDataLen = 0;
- if (aRange) {
- iDataLen = aRange[1]-aRange[0]+1;
- }
-
- if (fncCallback) {
- if (typeof(oHTTP.onload) != "undefined") {
- oHTTP.onload = function() {
- if (oHTTP.status == "200" || oHTTP.status == "206" || oHTTP.status == "0") {
- oHTTP.binaryResponse = new BinaryFile(oHTTP.responseText, iDataOffset, iDataLen);
- oHTTP.fileSize = iFileSize || oHTTP.getResponseHeader("Content-Length");
- fncCallback(oHTTP);
- } else {
- if (fncError) fncError();
- }
- oHTTP = null;
- };
- } else {
- oHTTP.onreadystatechange = function() {
- if (oHTTP.readyState == 4) {
- if (oHTTP.status == "200" || oHTTP.status == "206" || oHTTP.status == "0") {
- // IE6 craps if we try to extend the XHR object
- var oRes = {
- status : oHTTP.status,
- // IE needs responseBody, Chrome/Safari needs responseText
- binaryResponse : new BinaryFile(
- typeof oHTTP.responseBody == "unknown" ? oHTTP.responseBody : oHTTP.responseText, iDataOffset, iDataLen
- ),
- fileSize : iFileSize || oHTTP.getResponseHeader("Content-Length")
- };
- fncCallback(oRes);
- } else {
- if (fncError) fncError();
- }
- oHTTP = null;
- }
- };
- }
- }
- oHTTP.open("GET", strURL, true);
-
- if (oHTTP.overrideMimeType) oHTTP.overrideMimeType('text/plain; charset=x-user-defined');
-
- if (aRange && bAcceptRanges) {
- oHTTP.setRequestHeader("Range", "bytes=" + aRange[0] + "-" + aRange[1]);
- }
-
- oHTTP.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 1970 00:00:00 GMT");
-
- oHTTP.send(null);
- } else {
- if (fncError) fncError();
- }
- }
-
- return function(strURL, fncCallback, fncError, aRange) {
-
- if (aRange) {
- getHead(
- strURL,
- function(oHTTP) {
- var iLength = parseInt(oHTTP.getResponseHeader("Content-Length"),10);
- var strAcceptRanges = oHTTP.getResponseHeader("Accept-Ranges");
-
- var iStart, iEnd;
- iStart = aRange[0];
- if (aRange[0] < 0)
- iStart += iLength;
- iEnd = iStart + aRange[1] - 1;
-
- sendRequest(strURL, fncCallback, fncError, [iStart, iEnd], (strAcceptRanges == "bytes"), iLength);
- }
- );
-
- } else {
- sendRequest(strURL, fncCallback, fncError);
- }
- }
-
-}());
-
-/*
-document.write(
- "<script type='text/vbscript'>\r\n"
- + "Function IEBinary_getByteAt(strBinary, iOffset)\r\n"
- + " IEBinary_getByteAt = AscB(MidB(strBinary,iOffset+1,1))\r\n"
- + "End Function\r\n"
- + "Function IEBinary_getLength(strBinary)\r\n"
- + " IEBinary_getLength = LenB(strBinary)\r\n"
- + "End Function\r\n"
- + "</script>\r\n"
-);
-*/
-
-document.write(
- "<script type='text/vbscript'>\r\n"
- + "Function IEBinary_getByteAt(strBinary, iOffset)\r\n"
- + " IEBinary_getByteAt = AscB(MidB(strBinary, iOffset + 1, 1))\r\n"
- + "End Function\r\n"
- + "Function IEBinary_getBytesAt(strBinary, iOffset, iLength)\r\n"
- + " Dim aBytes()\r\n"
- + " ReDim aBytes(iLength - 1)\r\n"
- + " For i = 0 To iLength - 1\r\n"
- + " aBytes(i) = IEBinary_getByteAt(strBinary, iOffset + i)\r\n"
- + " Next\r\n"
- + " IEBinary_getBytesAt = aBytes\r\n"
- + "End Function\r\n"
- + "Function IEBinary_getLength(strBinary)\r\n"
- + " IEBinary_getLength = LenB(strBinary)\r\n"
- + "End Function\r\n"
- + "</script>\r\n"
-);
Oops, something went wrong.

0 comments on commit 4f5aa26

Please sign in to comment.