Skip to content

fix sz session abort #1

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,32 @@ class ZModemCore {

final ZModemTextHandler? onPlainText;

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();
}
_parser.addData(data);
// print('data: ${data.map((e) => e.toRadixString(16)).toList()}');

Expand Down
7 changes: 7 additions & 0 deletions lib/src/zmodem_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ class ZSessionFinishedEvent implements ZModemEvent {
return 'ZSessionFinishedEvent()';
}
}
/// The event fired when the ZModem aborted
class ZSessionAbortedEvent implements ZModemEvent {
@override
String toString() {
return 'ZSessionAbortedEvent()';
}
}

/// The other side is ready to receive a file.
class ZReadyToSendEvent implements ZModemEvent {
Expand Down
1 change: 0 additions & 1 deletion lib/src/zmodem_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class ZModemParser implements Iterator<ZModemPacket> {
/// and it's impossible to distinguish between plain text and a data subpacket
/// without this prompt....
void expectDataSubpacket() {
print('expectDataSubpacket');
_expectDataSubpacket = true;
}

Expand Down