source: trunk/dbc/stream.php@ 89

Last change on this file since 89 was 89, checked in by george, 16 years ago
  • Přidáno: Funkce pro export do DBC souborů. Zatím veřejně nepovoleno v nabídce, protože doba generování 45 MB souboru Spells.dbc překračuje max. dobu vykonání PHP skriptu 30 sekund. Nutno zoptimalizovat.
File size: 2.1 KB
Line 
1<?php
2
3define('FILE_NOT_FOUND', 'Soubor nenalezen.');
4
5class FileStream
6{
7 private $Handle;
8 private $FileName;
9
10 function __construct()
11 {
12 $this->Handle = false;
13 }
14
15 function __destruct()
16 {
17 if($this->Handle)
18 fclose($this->Handle);
19 }
20
21 public function OpenFile($FileName)
22 {
23 $this->FileName = $FileName;
24 $this->CloseFile();
25 $this->Handle = fopen($FileName, 'rb');
26 if(!$this->Handle) die(FILE_NOT_FOUND);
27 }
28
29 public function CreateFile($FileName)
30 {
31 $this->FileName = $FileName;
32 $this->CloseFile();
33 $this->Handle = fopen($FileName, 'wb+');
34 if(!$this->Handle) die(FILE_NOT_FOUND);
35 }
36
37 public function CloseFile()
38 {
39 if($this->Handle)
40 fclose($this->Handle);
41 }
42
43 public function ReadByte()
44 {
45 return(fread($this->Handle, 1));
46 }
47
48 public function ReadUint()
49 {
50 $val = unpack('V*', fread($this->Handle, 4));
51 return($val[1]);
52 }
53
54 public function ReadInt()
55 {
56 $val = unpack('I*', fread($this->Handle, 4));
57 return($val[1]);
58 }
59
60 public function ReadFloat()
61 {
62 $val = unpack('f*', fread($this->Handle, 4));
63 return($val[1]);
64 }
65
66 public function ReadChar()
67 {
68 return(fread($this->Handle, 1));
69 }
70
71 public function WriteByte($Value)
72 {
73 fwrite($this->Handle, pack('C*', $Value), 1);
74 }
75
76 public function WriteUint($Value)
77 {
78 fwrite($this->Handle, pack('V*', $Value), 4);
79 }
80
81 public function WriteInt($Value)
82 {
83 fwrite($this->Handle, pack('I*', $Value), 4);
84 }
85
86 public function WriteFloat($Value)
87 {
88 fwrite($this->Handle, pack('f*', $Value), 4);
89 }
90
91 public function WriteChar($Value)
92 {
93 fwrite($this->Handle, $Value, 1);
94 }
95
96 public function WriteString($Value)
97 {
98 fwrite($this->Handle, $Value);
99 fwrite($this->Handle, "\0", 1);
100 }
101
102 public function Seek($Position, $Type = SEEK_SET)
103 {
104 fseek($this->Handle, $Position, $Type);
105 }
106
107 public function GetPosition()
108 {
109 return(ftell($this->Handle));
110 }
111
112 public function GetSize()
113 {
114 return(filesize($this->FileName));
115 }
116}
117
118?>
Note: See TracBrowser for help on using the repository browser.