November 28, 2020, 11:05:51 AM

Author Topic: [bb] ReadFileAsString$() by Difference [ 1+ years ago ]  (Read 485 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] ReadFileAsString$() by Difference [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : ReadFileAsString$()
Author : Difference
Posted : 1+ years ago

Description : Read a file into a string, fast.

Code :
Code: BlitzBasic
  1. Function ReadFileAsString$(file$)
  2.  
  3.         Local tmp$=SystemProperty ("tempdir") + MilliSecs() + "bbrsrf.tmp"
  4.         Local ret$
  5.         Local fbank=CreateBank( FileSize(file$))
  6.  
  7.         f=OpenFile (file$)
  8.                 If Not f FreeBank fbank : Return ""
  9.        
  10.                 ReadBytes fbank,f,0,BankSize(fbank)    
  11.         CloseFile f
  12.        
  13.         f=WriteFile (tmp$)
  14.                 If Not f FreeBank fbank : Return ""
  15.                 WriteInt f,BankSize(fbank)
  16.                 WriteBytes fbank,f,0,BankSize(fbank)
  17.         CloseFile f
  18.  
  19.         f=OpenFile(tmp$)
  20.                 If Not f FreeBank fbank : Return ""
  21.                 ret$=ReadString(f)
  22.         CloseFile f
  23.  
  24.         FreeBank fbank
  25.  
  26.         DeleteFile tmp$
  27.  
  28.         Return ret$
  29.  
  30. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal