Created
February 11, 2012 09:54
-
-
Save iggymacd/1798341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import('dart:io'); | |
void main() { | |
List<int> data = [0x00, 0x01, 0x10, 0x11, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff]; | |
ListInputStream stream = new ListInputStream(); | |
int count = 0; | |
ReceivePort donePort = new ReceivePort(); | |
stream.write(data); | |
void onData() { | |
print('bytes available on stream is ' + stream.available()); | |
List<int> x = new List<int>(2); | |
var bytesRead = stream.readInto(x); | |
Expect.equals(2, bytesRead); | |
Expect.equals(data[count++], x[0]); | |
Expect.equals(data[count++], x[1]); | |
donePort.toSendPort().send(count); | |
} | |
void onClose() { | |
print('in onClose'); | |
} | |
stream.dataHandler = onData; | |
stream.closeHandler = onClose; | |
donePort.receive((x,y){ | |
if(x == 10){ | |
int numofbytes = stream.available(); | |
print('bytes available on stream is $numofbytes'); | |
stream.close(); | |
donePort.close(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment