![]() |
#1 |
Member
![]() Posts: 20
Karma: 27
Join Date: Jul 2008
Device: PRS-505
|
File.seek() syntax/parameters/working
A question to programmers.
Do you know, how seek() works here? It definitely doesn't work like C fseek(). seek(N,0) works like fseek(N,1) from C. Do you know any way to seek to an absolute position? I find reopening the file each time I need to seek() quite an ugly solution... |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,671
Karma: 12205348
Join Date: Mar 2008
Device: Galaxy S, Nook w/CM7
|
I do not belive there is support but I'm not 100% positive, honestly I did not try to figure out if it worked or not, I went for implementing a solution that I knew worked. The way we got around this in the dictionary application was to use 'grep' and 'sed'. Also we noticed a performance issue from using SONY's default API, sed/grep gave us the speed performance needed to search through large files in a reponsive time frame.
See the source for detailed examples =X= Last edited by =X=; 07-30-2008 at 02:08 PM. Reason: updated explination |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() Posts: 20
Karma: 27
Join Date: Jul 2008
Device: PRS-505
|
Well, all I managed to ind out about seek is that it can move forward and backward only. And the param is relative. I came up with the following workaround - maybe it's not very beautiful but it works and is a drop-in replacement for most uses of new Stream.File().
It changes seek behavior from fseek(n,1) to fseek(n,0), but it can be easily extended to allow mode choosing (Probably the best thing would be mode 0-relative 1-from the beginning 2-from the end, to make it backward compatible) It also won't work for files, that are open for writting - it uses static fsize variable - if the size changes, the calculations won't be accurate any more - I'll need to chage all the write*() so that they update fsize... function File4(name,mode) { var z; if (!mode) mode='r'; z = new Stream.File(name,mode); z.fsize=z.bytesAvailable; z.oldseek=z.seek; z.seek=function(n) { this.oldseek(n-(this.fsize-this.bytesAvailable))} return z; } As for the method - I've read the source and that is why I've decided to use tree based index - if I keep offsets there, I can avoid grepping through the file and can read only a small fraction of data. It also frees me from one-line-per-word limitation - if I store offset and length in the index tree, I can index whatever I want. Greetz |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Converting Merged HTML file to Epub/PDF Not Working | MV64 | Calibre | 1 | 06-07-2010 07:48 PM |
Feature Wish: Save Search Parameters | BookwormDragon | Calibre | 22 | 04-09-2010 05:31 AM |
CHM file not working in FBreader | yolle | iRex | 6 | 03-25-2010 06:26 PM |
Mobipocket file (no DRM) not working on Iliad | CommanderROR | iRex | 3 | 07-18-2008 01:34 PM |