Page 1 of 2

PureFILE library : WinAPI based file functions

Posted: Wed Aug 10, 2005 3:53 pm
by gnozal
PureFILE library V1 (Last update : SEPT 10th 2008)

Overview

Code: Select all

This user library offers WinAPI based buffered file functions, usually faster than the genuine Purebasic ones, but with a similar syntax.
Functions
PB3.94 : http://gnozal.ucoz.com/PureFILE.htm
PB4.0x : http://gnozal.ucoz.com/PureFILE_.htm

Example

Code: Select all

If PureFILE_ReadFile(#PB_Any, "C:\PureBasic393\Compilers\APIFunctionListing.txt")
  While PureFILE_NotEof()
    PureFILE_ReadString()
  Wend
  PureFILE_CloseFile()
EndIf
;
If PureFILE_ReadFile(1, "C:\PureBasic393\Compilers\APIFunctionListing.txt")
  If PureFILE_CreateFile(2, "C:\PureBasic393\Compilers\APIFunctionListing2.txt")
    *Buffer = AllocateMemory(50000)
    If *Buffer
      BytesRead = PureFILE_ReadData(1, *Buffer, 50000)
      While BytesRead
        BytesWritten = PureFILE_WriteData(2, *Buffer, BytesRead)
        BytesRead = PureFILE_ReadData(1, *Buffer, 50000)
      Wend
      PureFILE_CloseFile(1)
      PureFILE_CloseFile(2)
      FreeMemory(*Buffer)
    EndIf
  EndIf
EndIf
;
If PureFILE_ReadTextFile(#PB_Any, "C:\PureBasic393\Program\bigtextfile.txt")
  While PureFILE_NotEof()
    Line.s = PureFILE_ReadString()
  Wend
  PureFILE_CloseFile()
  Debug Line
EndIf
Download :
Only available for Purebasic Windows x86 (v3.9x-4.3x)
PB3.94 : http://gnozal.ucoz.com/PureFILE.zip
PB4.00-4.10 : http://gnozal.ucoz.com/PureFILE_.zip
PB4.20 : http://gnozal.ucoz.com/PureFILE___.zip
PB4.30 : http://gnozal.ucoz.com/PureFILE_430.zip

Posted: Wed Aug 10, 2005 3:54 pm
by gnozal
Disclaimer
The goal of this library is to provide some WinAPI based file functions usually faster than the genuine ones, but with a similar syntax.
It is based on GPI's jaPBe source code (thanks). There is no FastFile code included, and it is not intended to compete with Ring's library.
I simply find it usefull.

Posted: Wed Aug 10, 2005 6:01 pm
by Justin
if you want something usefull use handles like the winapi does and forget the id pb style way

Posted: Thu Aug 11, 2005 1:16 pm
by jack
appreciate your efforts gnozal, opensource is fine as long as there are not too many strings atached/or you need a law degree to understand the licence, eg LGPL.
as for me, i don't touch GPL source at all, much prefer public domain. :)

Posted: Thu Aug 11, 2005 2:18 pm
by Dare2
As Jack said re sources/GPL, etc (on another thread) .. either give it away freely or keep it hidden.

(I bet he says that to all the girls)!

GPL does suck.

That said, closed libs are a liability for the user, as we have seen. Often.

It is not just the potential for the lib to be malignant, deliberately or otherwise.

With all the best intentions in the world, the author cannot release the sources if they're suddenly dead - "Oops" said the busdriver!

And then the user is stuck if the lib gets left behind. It's either a rewrite of the code or sticking with an older version of PB for some apps.

Better a DLL, and best is open source.

Posted: Thu Aug 11, 2005 2:26 pm
by gnozal
Dare2 wrote:With all the best intentions in the world, the author cannot release the sources if they're suddenly dead - "Oops" said the busdriver!
Yes, but it's also true for commercials libs like Purevision Gadgets and even Purebasic.
Dare2 wrote:It's either a rewrite of the code or sticking with an older version of PB for some apps. Better a DLL
If you have an obsolete lib you can embed the functions in a DLL using an older PB version and then use it with newer PB versions.

Posted: Thu Aug 11, 2005 2:31 pm
by Dare2
Points taken!
:)

(I'd never thought of the embedding bit!)

But I'll stick to what I can see. And understand. The latter limits me quite a bit. :)

Posted: Thu Aug 11, 2005 2:45 pm
by thefool
Dare2 wrote: .. And understand. The latter limits me quite a bit.
yeah, you are quite stupid sometimes..




:lol:

Posted: Thu Aug 11, 2005 3:11 pm
by Dare2
thefool wrote:yeah, you are quite stupid sometimes..
:lol:
hehe. :P

* Note to self: Payback required! *

Posted: Thu Aug 11, 2005 3:31 pm
by thefool
Dare2 wrote: * Note to self: Payback required! *
damn! well, lets c if you "dare 2" do that :o

Posted: Tue Oct 10, 2006 10:13 am
by Psychophanta
Hallo,
i need a fast stuff for file dealing.
So, i'd like to know wich lib is faster; the Gnozal one or the Rings one? :)

Posted: Tue Oct 10, 2006 10:51 am
by PB
> I think PB functions don't have buffering, but I may be wrong

They do, and the buffer size can even be changed:

Code: Select all

Syntax
FileBuffersSize(#File, Size)

Description
Change the size of the buffers for the specified file. This method is available for advanced users, to allow to tune the file access performances. The default buffer size is 4096 bytes per file. If the 'Size' is put to 0, then all caching is disabled, and all write operations are immediately written to the disk.

Note: For performance reason, the buffer size should be kept large enough (1028 seems to be ok as minimum). When buffers are used, the information is really written to the disk once the cache buffer is full or when the file is closed. The FlushFileBuffers() command allow to force the write of the cache buffer at any time.

Posted: Tue Oct 10, 2006 10:58 am
by netmaestro
I don't think either will be faster than v4's native file functions as they have been improved immensely over 3.94. I look at those 3rd party libs as being more or less "obsolete" since v4. Someone could correct me if I'm wrong.

Posted: Tue Oct 10, 2006 2:09 pm
by gnozal
The PureFILE library is faster than the genuine PB3.94 functions (I use it a lot).
But if you use PB4.00, you should use the genuine PB functions, since they are now buffered. The PB4.00 PureFILE version is only provided for compatibility reasons.

Posted: Wed Oct 11, 2006 4:20 pm
by Psychophanta
Thanks,
but i do a compare file program with pb4.0 and the " fc.exe /B " command (which comes with windows) is faster :o