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

Implement the StreamWritable #11

Closed
wants to merge 1 commit into from
Closed

Implement the StreamWritable #11

wants to merge 1 commit into from

Conversation

zero2hex
Copy link
Collaborator

Changes

  • Implement the StreamWritable
  • Modify the Buffer initializer

Examples

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...!

Implement the StreamWritable and modify the Buffer.
@zero2hex zero2hex closed this Feb 29, 2016
@zero2hex zero2hex deleted the fileio branch February 29, 2016 01:04
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

Successfully merging this pull request may close these issues.

None yet

1 participant