Changes
- Add Makefile for building the project
- Implement the StreamWritable
- Modify the Buffer initializer
Examples
Makefile
make [ all | Trevi | Lime | build | clean ]
- all: Download the Libuv from the github and compile. Then get Libuv.a for this project.
- Trevi: Compile the 'Trevi'.
- Lime: Compile the 'Lime'.
- build: Compile sources which you wrote.
- clean: Delete all files created while building.
Writable Stream
public class Writer: StreamWritable {
var data = [Int8]()
override func _write(chunk: Buffer, encoding: NSStringEncoding?, callback: writableCallback) {
data.appendContentsOf(chunk.data)
print("Adding: \(NSString(bytes: data, length: data.count, encoding: NSUTF8StringEncoding)!)")
callback(nil)
}
}
func onFinish() {
print("finish!!")
}
let writer = Writer()
writer.on("finish", onFinish)
for item in ["Hello ", "World ", "on ", "SWIFT"] {
writer.write(item)
}
writer.end("...!")
print(NSString(bytes: writer.data, length: writer.data.count, encoding: NSUTF8StringEncoding)!)
Result
Adding: Hello
Adding: Hello World
Adding: Hello World on
Adding: Hello World on SWIFT
Adding: Hello World on SWIFT...!
finish!!
Hello World on SWIFT...!