Guidance
指路人
g.yi.org
software / rapidq / Examples / File & Directory / QLZFileStream / QLZFileStream.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'
' QLZFileStream component, version 1.0.0
' Copyright (C) 2001 Pavel "EvilOne" Minayev
'
' This product is free for use in any kind of programs,
' including shareware and commercial
'


     $IFNDEF _LZ_INC
      $DEFINE _LZ_INC


      $INCLUDE "rapidq.inc"


      CONST LZ.Version = 1.00


      DECLARE FUNCTION LZOpenFile LIB "lz32" ALIAS "LZOpenFileA" _
       (lpFileName AS STRING, lpReOpenBuf AS LONG, wStyle AS LONG) AS LONG
      DECLARE SUB LZClose LIB "lz32" ALIAS "LZClose" _
       (hFile AS LONG)
      DECLARE FUNCTION LZRead LIB "lz32" ALIAS "LZRead" _
       (hFile AS LONG, lpBuffer AS LONG, cbRead AS LONG) AS LONG
      DECLARE FUNCTION LZSeek LIB "lz32" ALIAS "LZSeek" _
       (hFile AS LONG, lOffset AS LONG, iOrigin AS LONG) AS LONG


      STRUCT QLZFileStream EXTENDS QOBJECT: WITH QLZFileStream
PRIVATE:
       FHandle AS LONG

       SUB SetPosition(Position AS LONG)
        LZSeek(.FHandle, Position, 0)
       END SUB

PUBLIC:
       Position AS LONG PROPERTY SET SetPosition

       FUNCTION Handle AS LONG
        result = .FHandle
       END FUNCTION

       FUNCTION Size AS LONG
        DEFINT SavedPos = .Position
        result = LZSeek(.FHandle, 0, 2)
        LZSeek(.FHandle, SavedPos, 0)
       END FUNCTION

       FUNCTION EOF AS LONG
        result = .Position >= .Size
       END FUNCTION

       FUNCTION OPEN(FileName AS STRING) AS LONG
        DEFBYTE buf(200)
        .FHandle = LZOpenFile(FileName + CHR$(0), VARPTR(buf(0)), 0)
        .Position = 0
        result = .FHandle >= 0
       END FUNCTION

       SUB CLOSE
        LZClose(.FHandle)
       END SUB

       SUB Seek(Offset AS LONG, From AS LONG)
        .Position = LZSeek(.FHandle, Offset, From)
       END SUB

       FUNCTION READ(Buffer AS LONG, Count AS LONG) AS LONG
        result = LZRead(.FHandle, Buffer, Count)
        .Position += Count
       END FUNCTION

       FUNCTION Read% AS SHORT
        DEFSHORT x
        .READ(VARPTR(x), SIZEOF(result))
        result = x
       END FUNCTION

       FUNCTION READ& AS LONG
        DEFLNG x
        .READ(VARPTR(x), SIZEOF(result))
        result = x
       END FUNCTION

       FUNCTION READ? AS SHORT
        DEFBYTE x
        .READ(VARPTR(x), 1)
        result = x
       END FUNCTION

       FUNCTION READ?? AS WORD
        DEFWORD x
        .READ(VARPTR(x), SIZEOF(result))
        result = x
       END FUNCTION

       FUNCTION Read! AS SINGLE
        DEFSNG x
        .READ(VARPTR(x), SIZEOF(result))
        result = x
       END FUNCTION

       FUNCTION Read# AS DOUBLE
        DEFDBL x
        .READ(VARPTR(x), SIZEOF(result))
        result = x
       END FUNCTION

       FUNCTION Read$(Length AS LONG) AS STRING
        DEFSTR x = SPACE$(Length)
        .READ(VARPTR(x), Length)
        result = x
       END FUNCTION

       FUNCTION ReadNum(Num AS LONG) AS DOUBLE
        SELECT CASE Num
        CASE Num_SHORT
         result = .Read%
        CASE Num_LONG
         result = .READ&
        CASE Num_BYTE
         result = .READ?
        CASE Num_WORD
         result = .READ??
        CASE Num_SINGLE
         result = .Read!
        CASE Num_DOUBLE
         result = .Read#
        END SELECT
       END FUNCTION

       FUNCTION ReadStr(Length AS LONG) AS STRING
        result = .Read$(Length)
       END FUNCTION

       FUNCTION ReadBinStr(Length AS LONG) AS STRING
        result = .Read$(Length)
       END FUNCTION

       FUNCTION ReadLine AS STRING
        result = ""
        DEFBYTE ch = .READ?
        WHILE ch <> 10 AND NOT .EOF
         IF ch <> 13 THEN result = result + CHR$(ch)
         ch = .READ?
        WEND
       END FUNCTION

      END WITH: END STRUCT


     $ENDIF
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-4-19  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2001-08-24 17:22:34