Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sz一个无权限的文件后,终端显示异常 #196

Open
itzhoujun opened this issue Jun 25, 2024 · 2 comments
Open

sz一个无权限的文件后,终端显示异常 #196

itzhoujun opened this issue Jun 25, 2024 · 2 comments

Comments

@itzhoujun
Copy link

itzhoujun commented Jun 25, 2024

sz一个无权限的文件后,再输入其他字符时,显示有点异常。比如说我输入了5个字符,终端页面只会展示2个。

@itzhoujun
Copy link
Author

找到问题了。是zmodem协议上未处理abort sequence:
class ZModemAbortSequence implements ZModemPacket {
const ZModemAbortSequence();

static final abortSequence = Uint8List.fromList([
consts.CAN,
consts.CAN,
consts.CAN,
consts.CAN,
consts.CAN,
]);

@OverRide
Uint8List encode() {
return abortSequence;
}
}

@itzhoujun
Copy link
Author

参考处理方式:
修改zmodem模块

  bool _findSubSeq(Uint8List origin, Uint8List subSeq) {
    // 如果 b 是空数组,直接返回 true
    if (subSeq.isEmpty) return true;

    // 如果 a 的长度小于 b 的长度,直接返回 false
    if (origin.length < subSeq.length) return false;

    // 遍历 a 数组,检查是否存在连续的子序列与 b 相等
    for (int i = 0; i <= origin.length - subSeq.length; i++) {
      bool match = true;
      for (int j = 0; j < subSeq.length; j++) {
        if (origin[i + j] != subSeq[j]) {
          match = false;
          break;
        }
      }
      if (match) return true;
    }

    return false;
  }
   Iterable<ZModemEvent> receive(Uint8List data) sync* {
    if (_findSubSeq(data, ZModemAbortSequence.abortSequence)) {
      yield ZSessionAbortedEvent();
    }
   // other code ....
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant