| <!DOCTYPE html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title> |
| Class: OpenDal::IO |
| |
| — Documentation by YARD 0.9.38 |
| |
| </title> |
| |
| <link rel="stylesheet" href="../css/style.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../css/common.css" type="text/css" /> |
| |
| <script type="text/javascript"> |
| pathId = "OpenDal::IO"; |
| relpath = '../'; |
| </script> |
| |
| |
| <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> |
| |
| <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> |
| |
| |
| </head> |
| <body> |
| <div class="nav_wrap"> |
| <iframe id="nav" src="../class_list.html?1"></iframe> |
| <div id="resizer"></div> |
| </div> |
| |
| <div id="main" tabindex="-1"> |
| <div id="header"> |
| <div id="menu"> |
| |
| <a href="../_index.html">Index (I)</a> » |
| <span class='title'><span class='object_link'><a href="../OpenDal.html" title="OpenDal (module)">OpenDal</a></span></span> |
| » |
| <span class="title">IO</span> |
| |
| </div> |
| |
| <div id="search"> |
| |
| <a class="full_list_link" id="class_list_link" |
| href="../class_list.html"> |
| |
| <svg width="24" height="24"> |
| <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> |
| <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> |
| <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> |
| </svg> |
| </a> |
| |
| </div> |
| <div class="clear"></div> |
| </div> |
| |
| <div id="content"><h1>Class: OpenDal::IO |
| |
| |
| |
| </h1> |
| <div class="box_info"> |
| |
| <dl> |
| <dt>Inherits:</dt> |
| <dd> |
| <span class="inheritName">Object</span> |
| |
| <ul class="fullTree"> |
| <li>Object</li> |
| |
| <li class="next">OpenDal::IO</li> |
| |
| </ul> |
| <a href="#" class="inheritanceTree">show all</a> |
| |
| </dd> |
| </dl> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <dl> |
| <dt>Defined in:</dt> |
| <dd>src/io.rs<span class="defines">,<br /> |
| lib/opendal_ruby/io.rb</span> |
| </dd> |
| </dl> |
| |
| </div> |
| |
| <h2>Overview</h2><div class="docstring"> |
| <div class="discussion"> |
| <p><code>OpenDal::IO</code> is similar to Ruby's <code>IO</code> and <code>StringIO</code> for accessing files.</p> |
| |
| <p>You can't create an instance of <code>OpenDal::IO</code> except using <span class='object_link'><a href="Operator.html#open-instance_method" title="OpenDal::Operator#open (method)">Operator#open</a></span>.</p> |
| |
| <p>Constraints:</p> |
| |
| <ul> |
| <li>Only available for reading and writing</li> |
| <li>Writing doesn't support seek.</li> |
| </ul> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| |
| </div> |
| |
| |
| |
| |
| |
| |
| |
| <h2> |
| Instance Method Summary |
| <small><a href="#" class="summary_toggle">collapse</a></small> |
| </h2> |
| |
| <ul class="summary"> |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#binmode-instance_method" title="#binmode (instance method)">#<strong>binmode</strong> ⇒ nil </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Enables binary mode for the stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#binmode%3F-instance_method" title="#binmode? (instance method)">#<strong>binmode?</strong> ⇒ Boolean </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns if the stream is on binary mode.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#close-instance_method" title="#close (instance method)">#<strong>close</strong> ⇒ nil </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Close streams.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#close_read-instance_method" title="#close_read (instance method)">#<strong>close_read</strong> ⇒ nil </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Closes the read stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#close_write-instance_method" title="#close_write (instance method)">#<strong>close_write</strong> ⇒ nil </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Closes the write stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#closed%3F-instance_method" title="#closed? (instance method)">#<strong>closed?</strong> ⇒ Boolean </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns if streams are closed.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#closed_read%3F-instance_method" title="#closed_read? (instance method)">#<strong>closed_read?</strong> ⇒ Boolean </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns if the read stream is closed.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#closed_write%3F-instance_method" title="#closed_write? (instance method)">#<strong>closed_write?</strong> ⇒ Boolean </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns if the write stream is closed.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#eof-instance_method" title="#eof (instance method)">#<strong>eof</strong> ⇒ Boolean </a> |
| |
| |
| |
| (also: #eof?) |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Checks if the stream is at the end of the file.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#length-instance_method" title="#length (instance method)">#<strong>length</strong> ⇒ Integer </a> |
| |
| |
| |
| (also: #size) |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns the total length of the stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#pos=-instance_method" title="#pos= (instance method)">#<strong>pos=</strong>(new_position) ⇒ Object </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Sets the file position to <code>new_position</code>.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#readline-instance_method" title="#readline (instance method)">#<strong>readline</strong> ⇒ String </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Reads a single line from the stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#readlines-instance_method" title="#readlines (instance method)">#<strong>readlines</strong> ⇒ Array<String> </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Reads all lines from the stream into an array.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#rewind-instance_method" title="#rewind (instance method)">#<strong>rewind</strong> ⇒ Object </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Rewinds the stream to the beginning.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#seek-instance_method" title="#seek (instance method)">#<strong>seek</strong>(offset, whence) ⇒ Integer </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Moves the file position based on the offset and whence.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#tell-instance_method" title="#tell (instance method)">#<strong>tell</strong> ⇒ Integer </a> |
| |
| |
| |
| (also: #pos) |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Returns the current reader_position of the file pointer in the stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| <li class="public "> |
| <span class="summary_signature"> |
| |
| <a href="#write-instance_method" title="#write (instance method)">#<strong>write</strong>(buffer) ⇒ Integer </a> |
| |
| |
| |
| </span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <span class="summary_desc"><div class='inline'><p>Writes data to the stream.</p> |
| </div></span> |
| |
| </li> |
| |
| |
| </ul> |
| |
| |
| |
| |
| <div id="instance_method_details" class="method_details_list"> |
| <h2>Instance Method Details</h2> |
| |
| |
| <div class="method_details first"> |
| <h3 class="signature first" id="binmode-instance_method"> |
| |
| #<strong>binmode</strong> ⇒ <tt>nil</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Enables binary mode for the stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>nil</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| <p class="tag_title">Raises:</p> |
| <ul class="raise"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>IOError</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>when operate on a closed stream</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 136 |
| 137 |
| 138 |
| 139 |
| 140 |
| 141 |
| 142 |
| 143</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 136</span> |
| |
| fn binary_mode(ruby: &Ruby, rb_self: &Self) -> Result<(), Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| if let FileState::Closed = handle.state { |
| return Err(Error::new(ruby.exception_io_error(), "closed stream")); |
| } |
| handle.fmode = FMode::new(handle.fmode.bits() | FMode::BINARY_MODE); |
| Ok(()) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="binmode?-instance_method"> |
| |
| #<strong>binmode?</strong> ⇒ <tt>Boolean</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns if the stream is on binary mode.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Boolean</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| <p class="tag_title">Raises:</p> |
| <ul class="raise"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>IOError</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>when operate on a closed stream</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 150 |
| 151 |
| 152 |
| 153 |
| 154 |
| 155 |
| 156</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 150</span> |
| |
| fn is_binary_mode(ruby: &Ruby, rb_self: &Self) -> Result<bool, Error> { |
| let handle = rb_self.0.borrow(); |
| if let FileState::Closed = handle.state { |
| return Err(Error::new(ruby.exception_io_error(), "closed stream")); |
| } |
| Ok(handle.fmode.contains(FMode::BINARY_MODE)) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="close-instance_method"> |
| |
| #<strong>close</strong> ⇒ <tt>nil</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Close streams.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>nil</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 162 |
| 163 |
| 164 |
| 165 |
| 166 |
| 167 |
| 168 |
| 169</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 162</span> |
| |
| fn close(ruby: &Ruby, rb_self: &Self) -> Result<(), Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| if let FileState::Writer(writer) = &mut handle.state { |
| writer.close().map_err(|err| format_io_error(ruby, err))?; |
| } |
| handle.state = FileState::Closed; |
| Ok(()) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="close_read-instance_method"> |
| |
| #<strong>close_read</strong> ⇒ <tt>nil</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Closes the read stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>nil</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 175 |
| 176 |
| 177 |
| 178 |
| 179 |
| 180 |
| 181</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 175</span> |
| |
| fn close_read(&self) -> Result<(), Error> { |
| let mut handle = self.0.borrow_mut(); |
| if let FileState::Reader(_) = &handle.state { |
| handle.state = FileState::Closed; |
| } |
| Ok(()) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="close_write-instance_method"> |
| |
| #<strong>close_write</strong> ⇒ <tt>nil</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Closes the write stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>nil</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 187 |
| 188 |
| 189 |
| 190 |
| 191 |
| 192 |
| 193 |
| 194</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 187</span> |
| |
| fn close_write(ruby: &Ruby, rb_self: &Self) -> Result<(), Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| if let FileState::Writer(writer) = &mut handle.state { |
| writer.close().map_err(|err| format_io_error(ruby, err))?; |
| handle.state = FileState::Closed; |
| } |
| Ok(()) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="closed?-instance_method"> |
| |
| #<strong>closed?</strong> ⇒ <tt>Boolean</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns if streams are closed.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Boolean</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 200 |
| 201 |
| 202 |
| 203</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 200</span> |
| |
| fn is_closed(&self) -> Result<bool, Error> { |
| let handle = self.0.borrow(); |
| Ok(matches!(handle.state, FileState::Closed)) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="closed_read?-instance_method"> |
| |
| #<strong>closed_read?</strong> ⇒ <tt>Boolean</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns if the read stream is closed.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Boolean</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 209 |
| 210 |
| 211 |
| 212</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 209</span> |
| |
| fn is_closed_read(&self) -> Result<bool, Error> { |
| let handle = self.0.borrow(); |
| Ok(!matches!(handle.state, FileState::Reader(_))) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="closed_write?-instance_method"> |
| |
| #<strong>closed_write?</strong> ⇒ <tt>Boolean</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns if the write stream is closed.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Boolean</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 218 |
| 219 |
| 220 |
| 221 |
| 222</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 218</span> |
| |
| fn is_closed_write(&self) -> Result<bool, Error> { |
| let handle = self.0.borrow(); |
| Ok(!matches!(handle.state, FileState::Writer(_))) |
| } |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="eof-instance_method"> |
| |
| #<strong>eof</strong> ⇒ <tt>Boolean</tt> |
| |
| |
| |
| <span class="aliases">Also known as: |
| <span class="names"><span id='eof?-instance_method'>eof?</span></span> |
| </span> |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Checks if the stream is at the end of the file.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Boolean</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 52 |
| 53 |
| 54 |
| 55 |
| 56</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'lib/opendal_ruby/io.rb', line 52</span> |
| |
| <span class='kw'>def</span> <span class='id identifier rubyid_eof'>eof</span> |
| <span class='id identifier rubyid_position'>position</span> <span class='op'>=</span> <span class='id identifier rubyid_tell'>tell</span> |
| <span class='id identifier rubyid_seek'>seek</span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>IO</span><span class='op'>::</span><span class='const'>SEEK_END</span><span class='rparen'>)</span> |
| <span class='id identifier rubyid_tell'>tell</span> <span class='op'>==</span> <span class='id identifier rubyid_position'>position</span> |
| <span class='kw'>end</span></pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="length-instance_method"> |
| |
| #<strong>length</strong> ⇒ <tt>Integer</tt> |
| |
| |
| |
| <span class="aliases">Also known as: |
| <span class="names"><span id='size-instance_method'>size</span></span> |
| </span> |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns the total length of the stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 62 |
| 63 |
| 64 |
| 65 |
| 66</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'lib/opendal_ruby/io.rb', line 62</span> |
| |
| <span class='kw'>def</span> <span class='id identifier rubyid_length'>length</span> |
| <span class='id identifier rubyid_current_position'>current_position</span> <span class='op'>=</span> <span class='id identifier rubyid_tell'>tell</span> |
| <span class='id identifier rubyid_seek'>seek</span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>IO</span><span class='op'>::</span><span class='const'>SEEK_END</span><span class='rparen'>)</span> |
| <span class='id identifier rubyid_tell'>tell</span><span class='period'>.</span><span class='id identifier rubyid_tap'>tap</span> <span class='lbrace'>{</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_pos'>pos</span> <span class='op'>=</span> <span class='id identifier rubyid_current_position'>current_position</span> <span class='rbrace'>}</span> |
| <span class='kw'>end</span></pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="pos=-instance_method"> |
| |
| #<strong>pos=</strong>(new_position) ⇒ <tt>Object</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Sets the file position to <code>new_position</code>.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| <p class="tag_title">Parameters:</p> |
| <ul class="param"> |
| |
| <li> |
| |
| <span class='name'>new_position</span> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 44 |
| 45 |
| 46</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'lib/opendal_ruby/io.rb', line 44</span> |
| |
| <span class='kw'>def</span> <span class='id identifier rubyid_pos='>pos=</span><span class='lparen'>(</span><span class='id identifier rubyid_new_position'>new_position</span><span class='rparen'>)</span> |
| <span class='id identifier rubyid_seek'>seek</span><span class='lparen'>(</span><span class='id identifier rubyid_new_position'>new_position</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>IO</span><span class='op'>::</span><span class='const'>SEEK_SET</span><span class='rparen'>)</span> |
| <span class='kw'>end</span></pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="readline-instance_method"> |
| |
| #<strong>readline</strong> ⇒ <tt>String</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Reads a single line from the stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>String</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 289 |
| 290 |
| 291 |
| 292 |
| 293 |
| 294 |
| 295 |
| 296 |
| 297 |
| 298 |
| 299 |
| 300 |
| 301 |
| 302 |
| 303 |
| 304 |
| 305 |
| 306 |
| 307 |
| 308 |
| 309 |
| 310 |
| 311</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 289</span> |
| |
| fn readline(ruby: &Ruby, rb_self: &Self) -> Result<String, Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| |
| if let FileState::Reader(reader) = &mut handle.state { |
| let mut buffer = String::new(); |
| let size = reader |
| .read_line(&mut buffer) |
| .map_err(|err| format_io_error(ruby, err))?; |
| if size == 0 { |
| return Err(Error::new( |
| ruby.exception_eof_error(), |
| "end of file reached", |
| )); |
| } |
| |
| Ok(buffer) |
| } else { |
| Err(Error::new( |
| ruby.exception_runtime_error(), |
| "I/O operation failed for reading on write-only file.", |
| )) |
| } |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="readlines-instance_method"> |
| |
| #<strong>readlines</strong> ⇒ <tt>Array<String></tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Reads all lines from the stream into an array.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Array<String></tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| <p class="tag_title">Raises:</p> |
| <ul class="raise"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>EOFError</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>when the end of the file is reached.</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 25 |
| 26 |
| 27 |
| 28 |
| 29 |
| 30 |
| 31 |
| 32 |
| 33 |
| 34 |
| 35</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'lib/opendal_ruby/io.rb', line 25</span> |
| |
| <span class='kw'>def</span> <span class='id identifier rubyid_readlines'>readlines</span> |
| <span class='id identifier rubyid_results'>results</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> |
| |
| <span class='id identifier rubyid_loop'>loop</span> <span class='kw'>do</span> |
| <span class='id identifier rubyid_results'>results</span> <span class='op'><<</span> <span class='id identifier rubyid_readline'>readline</span> |
| <span class='kw'>rescue</span> <span class='const'>EOFError</span> |
| <span class='kw'>break</span> |
| <span class='kw'>end</span> |
| |
| <span class='id identifier rubyid_results'>results</span> |
| <span class='kw'>end</span></pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="rewind-instance_method"> |
| |
| #<strong>rewind</strong> ⇒ <tt>Object</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Rewinds the stream to the beginning.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 38 |
| 39 |
| 40</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'lib/opendal_ruby/io.rb', line 38</span> |
| |
| <span class='kw'>def</span> <span class='id identifier rubyid_rewind'>rewind</span> |
| <span class='id identifier rubyid_seek'>seek</span><span class='lparen'>(</span><span class='int'>0</span><span class='comma'>,</span> <span class='op'>::</span><span class='const'>IO</span><span class='op'>::</span><span class='const'>SEEK_SET</span><span class='rparen'>)</span> |
| <span class='kw'>end</span></pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="seek-instance_method"> |
| |
| #<strong>seek</strong>(offset, whence) ⇒ <tt>Integer</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Moves the file position based on the offset and whence.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| <p class="tag_title">Parameters:</p> |
| <ul class="param"> |
| |
| <li> |
| |
| <span class='name'>offset</span> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>The position offset.</p> |
| </div> |
| |
| </li> |
| |
| <li> |
| |
| <span class='name'>whence</span> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>The reference point:</p> |
| |
| <ul> |
| <li>0 = IO:SEEK_SET (Start)</li> |
| <li>1 = IO:SEEK_CUR (Current position)</li> |
| <li>2 = IO:SEEK_END (From the end)</li> |
| </ul> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>always 0 if the seek operation is successful</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 347 |
| 348 |
| 349 |
| 350 |
| 351 |
| 352 |
| 353 |
| 354 |
| 355 |
| 356 |
| 357 |
| 358 |
| 359 |
| 360 |
| 361 |
| 362 |
| 363 |
| 364 |
| 365 |
| 366 |
| 367 |
| 368 |
| 369 |
| 370 |
| 371 |
| 372 |
| 373 |
| 374 |
| 375 |
| 376 |
| 377 |
| 378 |
| 379 |
| 380 |
| 381 |
| 382 |
| 383 |
| 384 |
| 385 |
| 386 |
| 387 |
| 388 |
| 389 |
| 390 |
| 391 |
| 392 |
| 393 |
| 394 |
| 395 |
| 396 |
| 397 |
| 398 |
| 399 |
| 400 |
| 401</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 347</span> |
| |
| fn seek(ruby: &Ruby, rb_self: &Self, offset: i64, whence: u8) -> Result<u8, Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| |
| if let FileState::Reader(reader) = &mut handle.state { |
| // Calculate the new position first |
| let new_reader_position = match whence { |
| 0 => { |
| // SEEK_SET - absolute position |
| if offset < 0 { |
| return Err(Error::new( |
| ruby.exception_runtime_error(), |
| "Cannot seek to negative reader_position.", |
| )); |
| } |
| offset as u64 |
| } |
| 1 => { |
| // SEEK_CUR - relative to current position |
| let position = reader |
| .stream_position() |
| .map_err(|err| format_io_error(ruby, err))?; |
| if offset < 0 && (-offset as u64) > position { |
| return Err(Error::new( |
| ruby.exception_runtime_error(), |
| "Cannot seek before start of stream.", |
| )); |
| } |
| (position as i64 + offset) as u64 |
| } |
| 2 => { |
| // SEEK_END |
| let end_pos = reader |
| .seek(SeekFrom::End(0)) |
| .map_err(|err| format_io_error(ruby, err))?; |
| if offset < 0 && (-offset as u64) > end_pos { |
| return Err(Error::new( |
| ruby.exception_runtime_error(), |
| "Cannot seek before start of stream.", |
| )); |
| } |
| (end_pos as i64 + offset) as u64 |
| } |
| _ => return Err(Error::new(ruby.exception_arg_error(), "invalid whence")), |
| }; |
| |
| let _ = reader.seek(std::io::SeekFrom::Start(new_reader_position)); |
| } else { |
| return Err(Error::new( |
| ruby.exception_runtime_error(), |
| "Cannot seek from end on write-only stream.", |
| )); |
| } |
| |
| Ok(0) |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="tell-instance_method"> |
| |
| #<strong>tell</strong> ⇒ <tt>Integer</tt> |
| |
| |
| |
| <span class="aliases">Also known as: |
| <span class="names"><span id='pos-instance_method'>pos</span></span> |
| </span> |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Returns the current reader_position of the file pointer in the stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>the current reader_position in bytes</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| <p class="tag_title">Raises:</p> |
| <ul class="raise"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>IOError</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>when cannot operate on the operation mode</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 408 |
| 409 |
| 410 |
| 411 |
| 412 |
| 413 |
| 414 |
| 415 |
| 416 |
| 417 |
| 418 |
| 419 |
| 420 |
| 421 |
| 422 |
| 423 |
| 424</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 408</span> |
| |
| fn tell(ruby: &Ruby, rb_self: &Self) -> Result<u64, Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| |
| match &mut handle.state { |
| FileState::Reader(reader) => Ok(reader |
| .stream_position() |
| .map_err(|err| format_io_error(ruby, err))?), |
| FileState::Writer(_) => Err(Error::new( |
| ruby.exception_runtime_error(), |
| "I/O operation failed for reading on write only file.", |
| )), |
| FileState::Closed => Err(Error::new( |
| ruby.exception_runtime_error(), |
| "I/O operation failed for tell on closed stream.", |
| )), |
| } |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| <div class="method_details "> |
| <h3 class="signature " id="write-instance_method"> |
| |
| #<strong>write</strong>(buffer) ⇒ <tt>Integer</tt> |
| |
| |
| |
| |
| |
| </h3><div class="docstring"> |
| <div class="discussion"> |
| <p>Writes data to the stream.</p> |
| |
| |
| </div> |
| </div> |
| <div class="tags"> |
| <p class="tag_title">Parameters:</p> |
| <ul class="param"> |
| |
| <li> |
| |
| <span class='name'>buffer</span> |
| |
| |
| <span class='type'>(<tt>String</tt>)</span> |
| |
| |
| |
| </li> |
| |
| </ul> |
| |
| <p class="tag_title">Returns:</p> |
| <ul class="return"> |
| |
| <li> |
| |
| |
| <span class='type'>(<tt>Integer</tt>)</span> |
| |
| |
| |
| — |
| <div class='inline'><p>the written byte size</p> |
| </div> |
| |
| </li> |
| |
| </ul> |
| |
| </div><table class="source_code"> |
| <tr> |
| <td> |
| <pre class="lines"> |
| |
| |
| 318 |
| 319 |
| 320 |
| 321 |
| 322 |
| 323 |
| 324 |
| 325 |
| 326 |
| 327 |
| 328 |
| 329 |
| 330 |
| 331 |
| 332 |
| 333 |
| 334</pre> |
| </td> |
| <td> |
| <pre class="code"><span class="info file"># File 'src/io.rs', line 318</span> |
| |
| fn write(ruby: &Ruby, rb_self: &Self, bs: String) -> Result<usize, Error> { |
| let mut handle = rb_self.0.borrow_mut(); |
| |
| if let FileState::Writer(writer) = &mut handle.state { |
| let bytes_written = bs.len(); |
| writer |
| .write_all(bs.as_bytes()) |
| .map_err(|err| format_io_error(ruby, err))?; |
| Ok(bytes_written) |
| } else { |
| Err(Error::new( |
| ruby.exception_runtime_error(), |
| "I/O operation failed for writing on read-only file.", |
| )) |
| } |
| } |
| }</pre> |
| </td> |
| </tr> |
| </table> |
| </div> |
| |
| </div> |
| |
| </div> |
| |
| <div id="footer"> |
| Generated on Thu Jan 1 04:08:32 2026 by |
| <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> |
| 0.9.38 (ruby-3.3.10). |
| </div> |
| |
| </div> |
| </body> |
| </html> |