imgcli\pipe.mbt

28.6% · 2 / 7 points · 55 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # 管道输入输出(`-` 约定)
  3. 3///
  4. 4/// 约定与 ImageMagick / ffmpeg 一致:路径写 `-` 表示 stdin 或 stdout。
  5. 5/// 底层能力只在 native 目标存在(见 `stdio_stub.c`);非 native 目标返回
  6. 6/// `None` / `false`,由调用方转成 `UnsupportedFormat` 错误,保证四目标同签名。
  7. 7
  8. 8///|
  9. 9#cfg(target="native")
  10. 10extern "C" fn read_stdin_ffi() -> Bytes = "moonbit_imgcli_read_stdin"
  11. 11
  12. 12///|
  13. 13#cfg(target="native")
  14. 14#borrow(data)
  15. 15extern "C" fn write_stdout_ffi(data : Bytes) -> Unit = "moonbit_imgcli_write_stdout"
  16. 16
  17. 17///|
  18. 18/// 读 stdin 全量字节;非 native 目标返回 `None`。
  19. 19#cfg(target="native")
  20. 20pub fn read_stdin_bytes() -> Bytes? {
  21. 21○ Some(read_stdin_ffi())
  22. 22}
  23. 23
  24. 24///|
  25. 25/// 把二进制写到 stdout;非 native 目标返回 `false`。
  26. 26#cfg(target="native")
  27. 27pub fn write_stdout_bytes(data : Bytes) -> Bool {
  28. 28○ write_stdout_ffi(data)
  29. 29 true
  30. 30}
  31. 31
  32. 32///|
  33. 33#cfg(not(target="native"))
  34. 34pub fn read_stdin_bytes() -> Bytes? {
  35. 35○ None
  36. 36}
  37. 37
  38. 38///|
  39. 39#cfg(not(target="native"))
  40. 40pub fn write_stdout_bytes(data : Bytes) -> Bool {
  41. 41○ ignore(data)
  42. 42 false
  43. 43}
  44. 44
  45. 45///|
  46. 46/// 路径是否为 stdin 占位符。
  47. 47pub fn is_stdin_path(path : String) -> Bool {
  48. 48● path == "-"
  49. 49}
  50. 50
  51. 51///|
  52. 52/// 路径是否为 stdout 占位符。
  53. 53pub fn is_stdout_path(path : String) -> Bool {
  54. 54● path == "-"
  55. 55}