@@ -11,6 +11,21 @@ By: Lucas Teske
1111https://github.com/racerxdl/jpak
1212*/
1313
14+ /**
15+ * Base64 Enconding Base
16+ * @const
17+ * @type {string }
18+ */
19+ JPAK . Base64_Encoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ;
20+
21+ /**
22+ * Enable this to show debug messages
23+ * @const
24+ * @type {boolean }
25+ */
26+ JPAK . ShowMessages = false ;
27+
28+
1429/* IE10 Hack for ArrayBuffer Slice */
1530if ( ! ArrayBuffer . prototype . slice ) {
1631 ArrayBuffer . prototype . slice = function ( start , end ) {
@@ -26,7 +41,10 @@ if(!ArrayBuffer.prototype.slice) {
2641 } ;
2742} ;
2843
29- /* Clean all deleteValue from array */
44+ /**
45+ * Clean all deletedValue from array
46+ * @expose
47+ */
3048Array . prototype . clean = function ( deleteValue ) {
3149 for ( var i = 0 ; i < this . length ; i ++ ) {
3250 if ( this [ i ] == deleteValue ) {
@@ -37,21 +55,38 @@ Array.prototype.clean = function(deleteValue) {
3755 return this ;
3856} ;
3957
40- /* Start of JPAK Class Stuff */
58+ /**
59+ * JPAK Base Class
60+ * @expose
61+ */
4162var JPAK = function ( ) { } ;
4263
43- // Enable this to show Debug Messages
44- JPAK . ShowMessages = false ;
64+ window [ "JPAK" ] = JPAK ;
4565
46- // Auxiliary functions
47- // Convert Unsigned Int 8 Array Buffer to String
66+ /**
67+ * Convert Unsigned Int8 ArrayBuffer to String
68+ * @param {Uint8Array } uintArray
69+ * @return {string }
70+ */
4871JPAK . Uint8ArrayToString = function ( uintArray ) {
4972 var o = "" ;
5073 for ( var i = 0 ; i < uintArray . byteLength ; i ++ )
5174 o += String . fromCharCode ( uintArray [ i ] ) ;
5275 return o ;
5376}
5477
78+ /**
79+ * Provided for retro-compatibility.
80+ * @deprecated
81+ */
82+ var u8as = JPAK . Uint8ArrayToString ; // Provided for compatibility
83+
84+ /**
85+ * Convert a String to an ArrayBuffer using uint8
86+ * @expose
87+ * @param {string } str
88+ * @return {ArrayBuffer }
89+ */
5590JPAK . String2ArrayBuffer = function ( str ) {
5691 var buf = new ArrayBuffer ( str . length ) ;
5792 var bufView = new Uint8Array ( buf ) ;
@@ -60,11 +95,13 @@ JPAK.String2ArrayBuffer = function(str) {
6095 return buf ;
6196} ;
6297
63- var u8as = JPAK . Uint8ArrayToString ; // Provided for compatibility
64-
65- JPAK . Base64_Encoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' ;
66-
67- // Modified version from https://gist.github.com/jonleighton/958841
98+ /**
99+ * Returns a Base64 String from an ArrayBuffer
100+ * Modified version from https://gist.github.com/jonleighton/958841
101+ * @expose
102+ * @param {arrayBuffer } arrayBuffer
103+ * @return {string } base64
104+ */
68105JPAK . ArrayBufferToBase64 = function ( arrayBuffer ) {
69106 var base64 = ''
70107
@@ -115,13 +152,22 @@ JPAK.ArrayBufferToBase64 = function(arrayBuffer) {
115152
116153 return base64
117154} ;
118-
155+ /**
156+ * Logs a message, if enabled
157+ * @expose
158+ * @param {string } msg
159+ */
119160JPAK . log = function ( msg ) {
120161 if ( JPAK . ShowMessages )
121162 console . log ( msg ) ;
122163}
123164
124- // JPAKLoader
165+ /**
166+ * Constructor of JPAKLoader
167+ * @constructor
168+ * @expose
169+ * @param {Object{jpakfile} } params
170+ */
125171JPAK . jpakloader = function ( parameters ) {
126172 if ( parameters !== undefined ) {
127173 this . jpakfile = parameters . file ;
@@ -131,7 +177,12 @@ JPAK.jpakloader = function(parameters) {
131177 this . dataloaded = false ;
132178} ;
133179
134- // Searches a file on the cache
180+ /**
181+ * Searches for a file on the cache
182+ * Returns undefined if not found
183+ * @param {string } path
184+ * @return {Object } file
185+ */
135186JPAK . jpakloader . prototype . CacheLoad = function ( path ) {
136187 for ( var i = 0 ; i < this . filecache . length ; i ++ ) {
137188 if ( this . filecache [ i ] . path == path )
@@ -141,6 +192,9 @@ JPAK.jpakloader.prototype.CacheLoad = function(path) {
141192} ;
142193
143194// Loads the jpak file and process it
195+ /**
196+ * Loads the JPAK File and Process it
197+ */
144198JPAK . jpakloader . prototype . Load = function ( ) {
145199 if ( this . jpakfile !== undefined ) {
146200 // _this is used to reference the jpakloader object
@@ -197,7 +251,12 @@ JPAK.jpakloader.prototype.Load = function() {
197251 console . log ( "JPAK::jpakloader - No file to load!" ) ;
198252} ;
199253
200- // Gets the directory entry if exists.
254+ /**
255+ * Gets the directory entry if exists.
256+ * Returns undefined if not found
257+ * @param {string } path
258+ * @return {object } directoryentry
259+ */
201260JPAK . jpakloader . prototype . FindDirectoryEntry = function ( path ) {
202261 var base = this . filetable ;
203262 if ( this . dataloaded ) {
@@ -220,7 +279,12 @@ JPAK.jpakloader.prototype.FindDirectoryEntry = function(path) {
220279 return base ;
221280} ;
222281
223- // Gets the file entry if exists.
282+ /**
283+ * Gets the file entry if exists.
284+ * Returns undefined if not found
285+ * @param {string } path
286+ * @return {object } fileentry
287+ */
224288JPAK . jpakloader . prototype . FindFileEntry = function ( path ) {
225289 var pathblock = path . split ( "/" ) . clean ( "" ) ;
226290 var filename = pathblock [ pathblock . length - 1 ] ;
@@ -232,7 +296,12 @@ JPAK.jpakloader.prototype.FindFileEntry = function(path) {
232296 return undefined ;
233297} ;
234298
235- // Returns an object { "dirs" : [ arrayofdirs ], "files" : [ arrayoffiles ], "error" : "An error message, if happens" }
299+ /**
300+ * Lists the dir returning an object like:
301+ * { "dirs" : [ arrayofdirs ], "files" : [ arrayoffiles ], "error" : "An error message, if happens" }
302+ * @param {string } path
303+ * @return {object } dirlist
304+ */
236305JPAK . jpakloader . prototype . ls = function ( path ) {
237306 var out = { "files" : [ ] , "dirs" : [ ] } ;
238307 if ( this . dataloaded ) {
@@ -250,7 +319,13 @@ JPAK.jpakloader.prototype.ls = function(path) {
250319 return out ;
251320} ;
252321
253- // Returns a blob of the file. It looks in the cache for already loaded files.
322+ /**
323+ * Returns a blob of the file.
324+ * It looks in the cache for already loaded files.
325+ * @param {path } File Path
326+ * @param {type } File Mime Type
327+ * @return {Blob } File Blobs
328+ */
254329JPAK . jpakloader . prototype . GetFile = function ( path , type ) {
255330 var file = this . FindFileEntry ( path ) ;
256331 type = type || 'application/octet-binary' ;
@@ -270,7 +345,13 @@ JPAK.jpakloader.prototype.GetFile = function(path, type) {
270345 return undefined ;
271346} ;
272347
273- // Returns a url of the blob file. It looks in the cache for already loaded files.
348+ /**
349+ * Returns a url of blob file.
350+ * It looks in the cache for already loaded files.
351+ * @param {path } File Path
352+ * @param {type } File Mime Type
353+ * @return {url } File URL
354+ */
274355JPAK . jpakloader . prototype . GetFileURL = function ( path , type ) {
275356 var cache = this . CacheLoad ( path ) ;
276357 if ( cache == undefined ) {
@@ -285,7 +366,13 @@ JPAK.jpakloader.prototype.GetFileURL = function(path, type) {
285366 return cache . url ;
286367} ;
287368
288- // Returns an arraybuffer with file content. It looks in the cache for already loaded files.
369+ /**
370+ * Returns an arraybuffer with file content.
371+ * It looks in the cache for already loaded files.
372+ * @param {path } File Path
373+ * @param {type } File Mime Type
374+ * @return {ArrayBuffer } File Buffer
375+ */
289376JPAK . jpakloader . prototype . GetFileArrayBuffer = function ( path , type ) {
290377 var file = this . FindFileEntry ( path ) ;
291378 type = type || 'application/octet-binary' ;
@@ -307,6 +394,13 @@ JPAK.jpakloader.prototype.GetFileArrayBuffer = function(path, type) {
307394} ;
308395
309396// Returns an Base64 Encoded File Content. It looks in the cache for already loaded files.
397+ /**
398+ * Returns an Base64 Encoded File Content.
399+ * It looks in the cache for already loaded files.
400+ * @param {path } File Path
401+ * @param {type } File Mime Type
402+ * @return {string } Base64 String
403+ */
310404JPAK . jpakloader . prototype . GetBase64File = function ( path , type ) {
311405 var filedata = this . GetFileArrayBuffer ( path , type ) ;
312406 if ( filedata == undefined )
@@ -315,9 +409,15 @@ JPAK.jpakloader.prototype.GetBase64File = function(path, type) {
315409 return JPAK . ArrayBufferToBase64 ( filedata ) ;
316410} ;
317411
318- // Returns an HTML Data URI with File Content. It looks in the cache for already loaded files.
319- // Using HTML Data URI for Images, you can hide the load process from chrome Network Inspector
320- // I didnt find any place that you can find DataURI File
412+ /**
413+ * Returns an HTML Data URI with File Content.
414+ * It looks in the cache for already loaded files.
415+ * Using HTML Data URI for Images, you can hide the load process from chrome Network Inspector
416+ * I didnt find any place that you can find DataURI File
417+ * @param {path } File Path
418+ * @param {type } File Mime Type
419+ * @return {string } HTML Data URI
420+ */
321421JPAK . jpakloader . prototype . GetHTMLDataURIFile = function ( path , type , encoding ) {
322422 var b64 = this . GetBase64File ( path , type ) ;
323423 // HTML Data URI Format: data:[<MIME-type>][;charset=<encoding>][;base64],<data>
0 commit comments