https://github.com/ksss/mruby-io-copy_stream
IO.copy_stream method for mruby
https://github.com/ksss/mruby-io-copy_stream
mruby
Last synced: 7 months ago
JSON representation
IO.copy_stream method for mruby
- Host: GitHub
- URL: https://github.com/ksss/mruby-io-copy_stream
- Owner: ksss
- Created: 2017-06-11T04:49:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-12T03:43:17.000Z (almost 8 years ago)
- Last Synced: 2025-03-04T04:42:53.399Z (about 1 year ago)
- Topics: mruby
- Language: C
- Size: 48.8 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
mruby-io-copy_stream
=====
The implementation of `IO.copy_stream` method for mruby.
# Feature
- Support `pread(2)`
- Support `sendfile(2)` if linux
- It doesn't have dependency to IO library.
# Special spec of this library
- Use fd for system call if respond to `fileno` method.
- Use `read` and `write` method if doesn't have fd.
- Use `seek` method if doesn't have fd for src_offset option.
# Performance
```rb
# bigfile is 440MB text file
t = Time.now
IO.copy_stream("bigfile", "bigfile-copy")
puts Time.now - t
t = Time.now
File.open("bigfile") do |src|
IO.copy_stream(src, "bigfile-copy")
end
puts Time.now - t
t = Time.now
File.open("bigfile-copy", "w") do |dst|
IO.copy_stream("bigfile", dst)
end
puts Time.now - t
t = Time.now
File.open("bigfile") do |src|
File.open("bigfile-copy", "w") do |dst|
IO.copy_stream(src, dst)
end
end
puts Time.now - t
```
CRuby
```
$ ruby t.rb
0.407673
0.400015
0.395681
0.401305
```
mruby use this library with [mruby-io](https://github.com/iij/mruby-io)
```
$ mruby t.rb
0.452422
0.419008
0.403466
0.412026
```
# How to development with docker
```
$ docker-compose -f docker/docker-compose.yml build
$ docker-compose -f docker/docker-compose.yml run test
```
```
$ make test
```
# See also
https://ruby-doc.org/core-2.4.1/IO.html#method-c-copy_stream