awtk/docs/fscript_istream.md

358 lines
5.4 KiB
Markdown
Raw Normal View History

2021-01-12 14:29:47 +08:00
## istream 扩展函数
### 1.istream\_seek
2021-01-13 17:39:21 +08:00
> 定位到指定的偏移量。
----------------------------
#### 原型
```js
istream_seek(istream, offset) => bool
```
> 仅当输入流支持 seek 才能调用本函数。
2022-08-23 10:12:36 +08:00
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
istream_seek(a, 10);
```
2021-01-12 14:29:47 +08:00
### 2.istream\_tell
2021-01-13 17:39:21 +08:00
> 获取当前的偏移量。
----------------------------
#### 原型
```js
2021-01-14 09:23:11 +08:00
istream_tell(istream) => uint32_t
2021-01-13 17:39:21 +08:00
```
> 仅当输入流支持 tell 才能调用本函数。
2022-08-23 10:12:36 +08:00
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
istream_seek(a, 10);
print(istream_tell(a));
```
2021-01-12 14:29:47 +08:00
### 3.istream\_read\_uint8
2021-01-13 17:39:21 +08:00
> 读取 uint8_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_uint8(istream, timeout) => uint8_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_uint8(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 4.istream\_read\_uint16
2021-01-13 17:39:21 +08:00
> 读取 uint16_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_uint16(istream, timeout) => uint16_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_uint16(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 5.istream\_read\_uint32
2021-01-13 17:39:21 +08:00
> 读取 uint32_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_uint32(istream, timeout) => uint32_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_uint32(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 6.istream\_read\_uint64
2021-01-13 17:39:21 +08:00
> 读取 uint64_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_uint64(istream, timeout) => uint64_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_uint64(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 7.istream\_read\_int8
2021-01-13 17:39:21 +08:00
> 读取 int8_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_int8(istream, timeout) => int8_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_int8(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 8.istream\_read\_int16
2021-01-13 17:39:21 +08:00
> 读取 int16_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_int16(istream, timeout) => int16_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_int16(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 9.istream\_read\_int32
2021-01-13 17:39:21 +08:00
> 读取 int32_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_int32(istream, timeout) => int32_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_int32(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 10.istream\_read\_int64
2021-01-13 17:39:21 +08:00
> 读取 int64_t 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_int64(istream, timeout) => int64_t
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_int64(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 11.istream\_read\_float
2021-01-13 17:39:21 +08:00
> 读取 float 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_float(istream, timeout) => float
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_float(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 12.istream\_read\_double
2021-01-13 17:39:21 +08:00
> 读取 double 类型的数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_double(istream, timeout) => double
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_double(a));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 13.istream\_read\_string
2021-01-13 17:39:21 +08:00
> 读取指定长度的字符串。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_string(istream, size, timeout) => str
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_string(a, 10));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 14.istream\_read\_binary
2021-01-13 17:39:21 +08:00
> 读取指定长度的二进制数据。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_binary(istream, size, timeout) => binary
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_binary(a, 10));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 15.istream\_read\_line
2021-01-13 17:39:21 +08:00
> 读取一行的字符串。
----------------------------
#### 原型
```js
2022-08-23 10:12:36 +08:00
istream_read_line(istream, size, timeout) => str
```
> timeout 为选填参数。
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_read_line(a, 10));
2021-01-13 17:39:21 +08:00
```
2021-01-12 14:29:47 +08:00
### 16.istream\_is\_eos
2021-01-13 17:39:21 +08:00
> 判读数据是否读完。
----------------------------
#### 原型
```js
istream_is_eos(istream) => bool
```
2022-08-23 10:12:36 +08:00
#### 示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb");
2022-08-23 10:12:36 +08:00
print(istream_is_eos(a));
```
2021-01-12 14:29:47 +08:00
### 更多示例
```js
2022-08-23 10:34:55 +08:00
var a = istream_file_create("test.bin", "rb")
2021-01-12 14:29:47 +08:00
assert(istream_read_uint8(a)==1)
assert(istream_read_int8(a)==-1)
assert(istream_tell(a), 2)
assert(istream_read_uint16(a)==2)
assert(istream_read_int16(a)==-2)
assert(istream_tell(a), 6)
assert(istream_read_uint32(a)==3)
assert(istream_read_int32(a)==-3)
assert(istream_tell(a), 14)
assert(istream_read_uint64(a)==4)
assert(istream_read_int64(a)==-4)
assert(istream_tell(a), 30)
assert(istream_read_float(a)==5)
assert(istream_read_double(a)==-5)
assert(istream_tell(a), 42)
assert(istream_read_string(a, 5)=="hello")
assert(istream_tell(a), 47)
istream_read_binary(a, 5)
assert(istream_tell(a), 52)
assert(istream_seek(a, 0))
assert(istream_read_uint8(a)==1)
assert(istream_read_int8(a)==-1)
assert(istream_tell(a) == 2)
unset(a)
```