55namespace AndKom \Bitcoin \Blockchain ;
66
77use AndKom \BCDataStream \Reader ;
8+ use AndKom \Bitcoin \Blockchain \Exception \IOException ;
89
910/**
1011 * Class BlockFileReader
@@ -18,30 +19,30 @@ class BlockFileReader
1819 * @param $fp
1920 * @param int|null $pos
2021 * @return Block
21- * @throws Exception
22+ * @throws IOException
2223 */
2324 public function readBlockFromFile ($ fp , int $ pos = null ): Block
2425 {
2526 if (!is_resource ($ fp )) {
26- throw new Exception ('Invalid file resource. ' );
27+ throw new IOException ('Invalid file resource. ' );
2728 }
2829
2930 if ($ pos && fseek ($ fp , $ pos - 4 ) === false ) {
30- throw new Exception ('Unable to seek block file. ' );
31+ throw new IOException ('Unable to seek block file. ' );
3132 }
3233
3334 $ size = fread ($ fp , 4 );
3435
3536 if ($ size === false ) {
36- throw new Exception ('Unable to read block size. ' );
37+ throw new IOException ('Unable to read block size. ' );
3738 }
3839
3940 $ length = unpack ('V ' , $ size )[1 ];
4041
4142 $ data = fread ($ fp , $ length );
4243
4344 if ($ data === false ) {
44- throw new Exception ('Unable to read block data. ' );
45+ throw new IOException ('Unable to read block data. ' );
4546 }
4647
4748 return Block::parse (new Reader ($ data ));
@@ -51,14 +52,14 @@ public function readBlockFromFile($fp, int $pos = null): Block
5152 * @param string $file
5253 * @param int $pos
5354 * @return Block
54- * @throws Exception
55+ * @throws IOException
5556 */
5657 public function readBlock (string $ file , int $ pos ): Block
5758 {
5859 $ fp = fopen ($ file , 'r ' );
5960
6061 if (!$ fp ) {
61- throw new Exception ("Unable to open block file ' $ file'. " );
62+ throw new IOException ("Unable to open block file ' $ file'. " );
6263 }
6364
6465 $ block = $ this ->readBlockFromFile ($ fp , $ pos );
@@ -71,14 +72,14 @@ public function readBlock(string $file, int $pos): Block
7172 /**
7273 * @param string $file
7374 * @return \Generator
74- * @throws Exception
75+ * @throws IOException
7576 */
7677 public function read (string $ file ): \Generator
7778 {
7879 $ fp = fopen ($ file , 'r ' );
7980
8081 if (!$ fp ) {
81- throw new Exception ("Unable to open block file ' $ file'. " );
82+ throw new IOException ("Unable to open block file ' $ file'. " );
8283 }
8384
8485 while (fread ($ fp , 4 ) == static ::MAGIC ) {
0 commit comments