imgcli\io.mbt
50% · 6 / 12 points · 66 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// 文件 IO 的平台分叉:`imgtool` 是 native 工具,但库包本身要保持 - 3
/// 四目标可编译(`moon check --target all --deny-warn` 是仓库门禁), - 4
/// 因此 wasm/js 下给出同签名的拒绝实现而不是编译失败。 - 5
- 6
///| - 7
#cfg(target="native") - 8
pub fn read_bytes(path : String) -> Bytes raise @types.ImageError { - 9●
@fs.read_file(path) catch { - 10
_ => - 11●
raise @types.ImageError::Decode( - 12
@types.ErrorCode::InvalidArgument, - 13
"读取文件失败: \{path}", - 14
) - 15
} - 16
} - 17
- 18
///| - 19
#cfg(target="native") - 20
pub fn write_bytes(path : String, data : Bytes) -> Unit raise @types.ImageError { - 21●
@fs.write_file(path, data) catch { - 22
_ => - 23○
raise @types.ImageError::Process( - 24
@types.ErrorCode::InvalidArgument, - 25
"写入文件失败: \{path}", - 26
) - 27
} - 28
} - 29
- 30
///| - 31
#cfg(not(target="native")) - 32
pub fn read_bytes(path : String) -> Bytes raise @types.ImageError { - 33○
ignore(path) - 34
raise @types.ImageError::Decode( - 35
@types.ErrorCode::UnsupportedFormat, - 36
"imgtool 的读写依赖 native 文件系统,请以 native 目标构建", - 37
) - 38
} - 39
- 40
///| - 41
#cfg(not(target="native")) - 42
pub fn write_bytes(path : String, data : Bytes) -> Unit raise @types.ImageError { - 43○
ignore(path) - 44○
ignore(data) - 45
raise @types.ImageError::Process( - 46
@types.ErrorCode::UnsupportedFormat, - 47
"imgtool 的读写依赖 native 文件系统,请以 native 目标构建", - 48
) - 49
} - 50
- 51
///| - 52
#cfg(target="native") - 53
pub fn ensure_dir(path : String) -> Unit { - 54●
if path == "" || path == "." { - 55○
return - 56
} - 57●
@fs.create_dir(path) catch { - 58●
_ => () - 59
} - 60
} - 61
- 62
///| - 63
#cfg(not(target="native")) - 64
pub fn ensure_dir(path : String) -> Unit { - 65○
ignore(path) - 66
}