Hi, I have a FS dialplan that fetches callflow from a JSON file. File is read using var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result), Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON. Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF?
Hi , This will help you . https://wiki.freeswitch.org/wiki/File Raymond At 2017-06-22 21:49:33, "Faruq Ahmad" <afarooqa@gmail.com> wrote: Hi, I have a FS dialplan that fetches callflow from a JSON file. File is read using var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result), Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON. Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF?
That wiki documentation is from the old spidermonkey js module not the new v8 one. I believe that putting a very large number will not cause any problems as the data read cannot exceed the total bytes in the file so it should not be a problem. You can always do an append loop. Its usually a good practice to have a precise max size to read because what if the file was accidentally 2gb. On Fri, Jun 23, 2017 at 3:36 AM, Raymond <xxxman2008@126.com> wrote:
Hi ,
This will help you . https://wiki.freeswitch.org/wiki/File
Raymond
At 2017-06-22 21:49:33, "Faruq Ahmad" <afarooqa@gmail.com> wrote:
Hi,
I have a FS dialplan that fetches callflow from a JSON file. File is read using
var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result),
Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON.
Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF?
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬ ☞ http://freeswitch.org/ ☞ http://cluecon.com/ ☞ http://twitter.com/FreeSWITCH ☞ irc.freenode.net #freeswitch ☞ *http://freeswitch.org/g+ <http://freeswitch.org/g+>* ClueCon Weekly Development Call ☎ sip:888@conference.freeswitch.org ☎ +19193869900 https://www.youtube.com/watch?v=9XXgW34t40s https://www.youtube.com/watch?v=NLaDpGQuZDA
I consulted this wiki and File is not implemented for v8, only FileIo is available. I ended up doing something similar, var read_size = 2048; do { read_size *=2; var jsFd = new FileIO('/opt/prj_jsons/cfId.json', 'r'); jsFd.read(read_size); jsData = jsFd.data(); jsFd.close(); }while(jsData.length == read_size); its a good idea to put a cap on the read_size, i'll put a cap on after a few Mbs. I tried appending the new data to the incomplete read attempt, but after the first iteration the buffer wont clear and on last iteration data from previous read attempt was concatenated to the .data() output of the last read attempt after the data in file finished. if the data read cannot exceed the total bytes in the file I can get rid of this and safely just put the desired cap size in the read_size. Thanks. On Sat, Jun 24, 2017 at 1:00 AM, Anthony Minessale < anthony.minessale@gmail.com> wrote:
That wiki documentation is from the old spidermonkey js module not the new v8 one.
I believe that putting a very large number will not cause any problems as the data read cannot exceed the total bytes in the file so it should not be a problem. You can always do an append loop. Its usually a good practice to have a precise max size to read because what if the file was accidentally 2gb.
On Fri, Jun 23, 2017 at 3:36 AM, Raymond <xxxman2008@126.com> wrote:
Hi ,
This will help you . https://wiki.freeswitch.org/wiki/File
Raymond
At 2017-06-22 21:49:33, "Faruq Ahmad" <afarooqa@gmail.com> wrote:
Hi,
I have a FS dialplan that fetches callflow from a JSON file. File is read using
var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result),
Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON.
Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF?
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬
☞ http://freeswitch.org/ ☞ http://cluecon.com/ ☞ http://twitter.com/FreeSWITCH ☞ irc.freenode.net #freeswitch ☞ *http://freeswitch.org/g+ <http://freeswitch.org/g+>*
ClueCon Weekly Development Call ☎ sip:888@conference.freeswitch.org ☎ +19193869900 <(919)%20386-9900>
https://www.youtube.com/watch?v=9XXgW34t40s https://www.youtube.com/watch?v=NLaDpGQuZDA
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
OK, firstly ,where's the new documentation of new V8 js module ? Secondly, I think, loop read small piece of file will cause too much I/O request . SO , i usually do read in following way. open the file ----> get file size --> read the whole file ( OS will charge the "one time " read size). and in real-life , real-project , there's not so many big files. So, just open the file ,and read all. in 99.99% situation , it's safe. in some situation , you cann't open the "incomplete file" , you even cann't "see" them. There's too much detail when we talk about file read ,we can discuss file-system in rest of our life. For Faruq , i think just read whole file is ok . if you warry about "incomplete file" ,just wait 1 second ,and read the file size again. it's may casuse delay ,but useful if you have lots of files to read . In my opinion, when linux do file read ,it read 1 block one time . A block is a sequence of bit or Bytes with a fixed length ie 512 bytes, 4kB, 8kB, 16kB, 32kB etc. So , please not use strange number as your read size. it's not a good idea. And ......I really hate "while (.....)" code ,it's really really bad. Raymond At 2017-06-24 04:00:36, "Anthony Minessale" <anthony.minessale@gmail.com> wrote: That wiki documentation is from the old spidermonkey js module not the new v8 one. I believe that putting a very large number will not cause any problems as the data read cannot exceed the total bytes in the file so it should not be a problem. You can always do an append loop. Its usually a good practice to have a precise max size to read because what if the file was accidentally 2gb. On Fri, Jun 23, 2017 at 3:36 AM, Raymond <xxxman2008@126.com> wrote: Hi , This will help you . https://wiki.freeswitch.org/wiki/File Raymond At 2017-06-22 21:49:33, "Faruq Ahmad" <afarooqa@gmail.com> wrote: Hi, I have a FS dialplan that fetches callflow from a JSON file. File is read using var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result), Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON. Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF? _________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org -- Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬ ☞ http://freeswitch.org/ ☞ http://cluecon.com/ ☞ http://twitter.com/FreeSWITCH ☞ irc.freenode.net #freeswitch ☞ http://freeswitch.org/g+ ClueCon Weekly Development Call ☎ sip:888@conference.freeswitch.org ☎ +19193869900 https://www.youtube.com/watch?v=9XXgW34t40s https://www.youtube.com/watch?v=NLaDpGQuZDA
On Sun, Jun 25, 2017 at 1:29 PM Raymond <xxxman2008@126.com> wrote:
OK, firstly ,where's the new documentation of new V8 js module ?
Use the source luke. Maybe you can join the volunteer docs team and help them. The module itself was donated by a community member.
Secondly, I think, loop read small piece of file will cause too much I/O request . SO , i usually do read in following way. open the file ----> get file size --> read the whole file ( OS will charge the "one time " read size).
That is completely relevant to the size of the file and the size of the chunk. There is no one answer.
and in real-life , real-project , there's not so many big files. So, just open the file ,and read all. in 99.99% situation , it's safe.
Um, ok..... That does not sound very wise but sure. I'd say At least test the size of the file first.
in some situation , you cann't open the "incomplete file" , you even cann't "see" them. There's too much detail when we talk about file read ,we can discuss file-system in rest of our life. For Faruq , i think just read whole file is ok . if you warry about "incomplete file" ,just wait 1 second ,and read the file size again. it's may casuse delay ,but useful if you have lots of files to read .
In my opinion, when linux do file read ,it read 1 block one time . A block is a sequence of bit or Bytes with a fixed length ie 512 bytes, 4kB, 8kB, 16kB, 32kB etc. So , please not use strange number as your read size. it's not a good idea. And ......I really hate "while (.....)" code ,it's really really bad.
Shaming coding constructs, in my opinion, is the path to mistakes. Every code element exists for a reason and there is always a case for any of them. I hate coding construct x is not helpful.
Raymond
At 2017-06-24 04:00:36, "Anthony Minessale" <anthony.minessale@gmail.com> wrote:
That wiki documentation is from the old spidermonkey js module not the new v8 one.
I believe that putting a very large number will not cause any problems as the data read cannot exceed the total bytes in the file so it should not be a problem. You can always do an append loop. Its usually a good practice to have a precise max size to read because what if the file was accidentally 2gb.
On Fri, Jun 23, 2017 at 3:36 AM, Raymond <xxxman2008@126.com> wrote:
Hi ,
This will help you . https://wiki.freeswitch.org/wiki/File
Raymond
At 2017-06-22 21:49:33, "Faruq Ahmad" <afarooqa@gmail.com> wrote:
Hi,
I have a FS dialplan that fetches callflow from a JSON file. File is read using
var JsonFd = new FileIO(JsonPath, 'r'); JsonFd.read(2048); result = JsonFd.data(); var menu = JSON.parse(result),
Is there anyway I can read the whole file in one attempt, i.e. when a smaller size was given to the .read() function it wouldn't read the complete file. I have increased the value of size for read function however my concern is in the long run file size might increase and parse would get an incomplete JSON.
Is there anyway I can get filesize from FileIO object or detect EOF from the read buffer to make sure the whole file is loaded? Also if I increase the size for read fucntion buffer way over the estimated filesizes, is there any guarantee that no garbage values will be read from the disk after the EOF?
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬
☞ http://freeswitch.org/ ☞ http://cluecon.com/ ☞ http://twitter.com/FreeSWITCH ☞ irc.freenode.net #freeswitch ☞ *http://freeswitch.org/g+ <http://freeswitch.org/g+>*
ClueCon Weekly Development Call ☎ sip:888@conference.freeswitch.org ☎ +19193869900
https://www.youtube.com/watch?v=9XXgW34t40s https://www.youtube.com/watch?v=NLaDpGQuZDA
_________________________________________________________________________ Professional FreeSWITCH Consulting Services: consulting@freeswitch.org http://www.freeswitchsolutions.com
Official FreeSWITCH Sites http://www.freeswitch.org http://confluence.freeswitch.org http://www.cluecon.com
FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II ♬ @anthmfs ♬ @FreeSWITCH ♬ ☞ http://freeswitch.org/ ☞ http://cluecon.com/ ☞ http://twitter.com/FreeSWITCH ☞ irc.freenode.net #freeswitch ☞ *http://freeswitch.org/g+ <http://freeswitch.org/g+>* ClueCon Weekly Development Call ☎ sip:888@conference.freeswitch.org ☎ +19193869900 https://www.youtube.com/watch?v=9XXgW34t40s https://www.youtube.com/watch?v=NLaDpGQuZDA
participants (3)
-
Anthony Minessale
-
Faruq Ahmad
-
Raymond