This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:hexview [2015/07/13 00:58] stevegarman created |
sample_code:hexview [2015/07/29 21:17] stevegarman Handle large files in chunks |
||
---|---|---|---|
Line 2: | Line 2: | ||
===== Sample code ===== | ===== Sample code ===== | ||
<code JavaScript hexView.js> | <code JavaScript hexView.js> | ||
+ | var picker, | ||
// | // | ||
function OnStart() | function OnStart() | ||
{ | { | ||
- | |||
- | var path="/ | ||
// | // | ||
var lay = app.CreateLayout( " | var lay = app.CreateLayout( " | ||
Line 17: | Line 15: | ||
scroll.AddChild( layScroll ); | scroll.AddChild( layScroll ); | ||
- | var view=app.CreateWebView(1.5, | + | view=app.CreateWebView(1.5, |
layScroll.AddChild(view); | layScroll.AddChild(view); | ||
// | // | ||
app.AddLayout( lay ); | app.AddLayout( lay ); | ||
- | hexView(path, | + | var path="/ |
+ | hexViewStart(path, | ||
} | } | ||
+ | function hexViewStart(fullPath, | ||
+ | { | ||
+ | hv={chunksize: | ||
+ | hv.webView=webView; | ||
+ | hv.file = app.CreateFile( hv.path, | ||
+ | hv.len = hv.file.GetLength(); | ||
+ | hv.html="< | ||
+ | hv.file.Seek( 0 ); | ||
+ | app.ShowProgress(" | ||
+ | hexViewChunk(); | ||
+ | } | ||
- | function hexView(fullPath, | + | function hexViewChunk() |
{ | { | ||
- | var file = app.CreateFile( fullPath, "r" | + | var pos=hv.file.GetPointer(); |
- | var len = file.GetLength(); | + | var whole = hv.file.ReadData( hv.chunksize,"int" |
+ | if(whole == undefined) | ||
+ | { | ||
+ | hexViewEnd(); | ||
+ | return; | ||
+ | } | ||
var bull="& | var bull="& | ||
- | var html="< | + | var int, |
- | var int, | + | |
- | file.Seek( 0 ); | + | |
- | app.ShowProgress(" | + | |
- | var whole = file.ReadData( len," | + | |
do | do | ||
{ | { | ||
Line 42: | Line 53: | ||
// | // | ||
if(data==undefined) break; | if(data==undefined) break; | ||
- | len = data.length; | + | var len = data.length; |
hbuff=""; | hbuff=""; | ||
- | abuff="< | + | abuff="< |
var pos8="< | var pos8="< | ||
(" | (" | ||
Line 56: | Line 67: | ||
if(int> | if(int> | ||
asc=String.fromCharCode(int); | asc=String.fromCharCode(int); | ||
- | hbuff+="< | + | if(asc=="<" |
+ | hbuff+="< | ||
abuff+=asc; | abuff+=asc; | ||
} | } | ||
abuff+="</ | abuff+="</ | ||
row="< | row="< | ||
- | html +=row+" | + | if(len> |
pos+=len; | pos+=len; | ||
} | } | ||
while(len > | while(len > | ||
- | html+="</ | + | setTimeout(" |
+ | } | ||
+ | |||
+ | function hexViewEnd() | ||
+ | { | ||
+ | hv.html+="</ | ||
app.HideProgress(); | app.HideProgress(); | ||
- | webView.LoadHtml(html); | + | hv.webView.LoadHtml(hv.html); |
- | //alert(html); | + | hv.file.Close(); |
- | file.Close(); | + | } |
+ | |||
+ | function pickit() | ||
+ | { | ||
+ | if( ! picker ) | ||
+ | { | ||
+ | picker = new FilePicker(openit," | ||
+ | picker.SetFolder(" | ||
+ | picker.SetHideFiles(false); | ||
+ | } | ||
+ | picker.Show(picker); | ||
+ | |||
+ | } | ||
+ | function openit(pth) | ||
+ | { | ||
+ | hexViewStart(pth,view); | ||
} | } | ||
</ | </ |