Page 1 of 1
ReadFile oddities - synchronous, open specific local file
Posted: Mon Oct 09, 2017 10:00 pm
by mdp
I am having problems with ReadFile():
1) I need it to be synchronous: it opens a file for reading, I process it, and the main process does not continue until the operation is done. Instead, I get to use a callback...
2) the manual says « OpenFileRequester()() needs to be called before to have access to local files.» But I open the file as a data repository! How can I need to open a requester before!?
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Mon Oct 09, 2017 10:26 pm
by mdp
Not even `IncludeBinary` is there...
If the limitation is because of the JS concept of running in a browser from random web pages hence need for security, instead of being code run from a trusted application, well, then JS is not enough. It must be "patched" and augmented with the needed bits of "local OS".
Already the access to SQLite files is not there... How can one load data into the application?
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Mon Oct 09, 2017 10:53 pm
by falsam
mdp wrote:How can one load data into the application?
With Php :
https://www.spiderbasic.com/documentati ... quest.html
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 7:25 am
by Peter
mdp wrote:Already the access to SQLite files is not there... How can one load data into the application?
perhaps SpiderBite fulfils your requirements:
Code: Select all
; either include "SpiderBite.sbi":
; XIncludeFile "[YourPathTo]/SpiderBite.sbi"
;
; ... or copy "SpiderBite.res" to SpiderBasics Residents-Folder
#SpiderBite_Profile = "default"
Procedure GetDataCallback(Success, Result.s)
Debug "Success: " + Success
Debug "Result: " + Result
EndProcedure
EnablePbCgi
UseSQLiteDatabase()
ProcedureDLL.s GetData()
Protected ReturnValue.s
Protected DB
DB = OpenDatabase(#PB_Any, ":memory:", "", "", #PB_Database_SQLite)
If DB
DatabaseUpdate(DB, "Create Table SuperHeroes (Prename TEXT, Surname TEXT)")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Peter', 'Parker')")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Bruce', 'Wayne')")
DatabaseUpdate(DB, "Insert Into SuperHeroes (Prename, Surname) Values ('Clark', 'Kent')")
If DatabaseQuery(DB, "Select * From SuperHeroes Where Prename = 'Peter'")
While NextDatabaseRow(DB)
ReturnValue + GetDatabaseString(DB, 1) + "," + GetDatabaseString(DB, 0) + #CRLF$
Wend
FinishDatabaseQuery(DB)
EndIf
CloseDatabase(DB)
EndIf
ProcedureReturn ReturnValue
EndProcedure
DisablePbCgi
GetData()
If 1=2 ; prevent removing the 'unneeded' callback
GetDataCallback(0, "")
EndIf
Further informations:
https://github.com/spiderbytes/SpiderBite
(the documentation is in german, but you can use DeepL for the translation)
Greetings ... Peter
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 8:36 am
by mdp
Sorry, I don't get it... Do you mean using a network server? It is totally overkill. This approach would restrict SB to client-server applications. To use SB for local application development, possibly offline, we need to access data. This mean custom binary/text (e.g. CSV, "blit" etc.), DB (SQLite) etc.
EDIT: unless SB packs a minimal, maybe transparent server... It's not impossible to implement, and it can be done with minimal libraries! It's a hack, but we need a hack to make full applications out of web-based code.
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 1:37 pm
by mdp
At the moment, I thought that the best solution seems to embed a JSON literal with IncludeFile.
Am I missing anything? Are there better ideas?
I would love to access the blit of an array of structures, but never tried even in PB...
I would also like to free the memory of source literal objects - just to do things properly.
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 2:02 pm
by Peter
mdp wrote:Are there better ideas?
perhaps your Json-File with LoadJson()?
btw.: what is a 'blit'?
Greetings ... Peter
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 3:33 pm
by mdp
Peter wrote:perhaps your Json-File with LoadJson()?
You mean we cannot access random local files but we can if they are JSON formatted (which does not even have a magic header?). I am stunned, it would make no sense
Peter wrote:btw.: what is a 'blit'?
It's when you dump a piece of memory (low level) that you can then load to use it with high level functions. E.g. if you have an array of 10 of a structure of a byte and an int, you could use a dump of 50 bytes as both storage and of source to load into memory. But put in there pointers (e.g. null-terminated strings), and the matter gets messy...
So basically I meant: something that you upload into memory and use directly
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 3:41 pm
by mdp
mdp wrote:You mean we cannot access random local files but we can if they are JSON formatted (which does not even have a magic header?). I am stunned, it would make no sense
And in fact, I may be wrong, but the manual seems to indicate using a procedure which is part of the Requester library:
Filename$ The name of the file containing the JSON data. It can be an URL or a local file identifier got with SelectedFileID().
Re: ReadFile oddities - synchronous, open specific local fil
Posted: Tue Oct 10, 2017 4:24 pm
by Peter
you can use LoadJSON() without Requester:
Code: Select all
Procedure Loaded(Type, Filename$, ObjectId)
Debug Type
Debug Filename$
Debug ObjectId
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
EndProcedure
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadJSON(0, "./resources/test.json")
Greetings ... Peter