forked from apache/opendal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer.rs
61 lines (52 loc) · 1.91 KB
/
writer.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use std::task::Context;
use std::task::Poll;
use futures::FutureExt;
use hdfs_native::file::FileWriter;
use crate::raw::oio;
use crate::raw::oio::WriteBuf;
use crate::*;
use super::error::parse_hdfs_error;
pub struct HdfsNativeWriter {
f: FileWriter,
}
impl HdfsNativeWriter {
pub fn new(f: FileWriter) -> Self {
HdfsNativeWriter { f }
}
}
impl oio::Write for HdfsNativeWriter {
fn poll_write(&mut self, cx: &mut Context<'_>, bs: &dyn WriteBuf) -> Poll<Result<usize>> {
println!("HdfsNativeWriter::poll_write{}", bs.remaining());
Box::pin(self.f.write(bs.bytes(bs.remaining())))
.poll_unpin(cx)
.map_err(parse_hdfs_error)
}
fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll<Result<()>> {
println!("HdfsNativeWriter::poll_close");
Box::pin(self.f.close())
.poll_unpin(cx)
.map_err(parse_hdfs_error)
}
fn poll_abort(&mut self, _cx: &mut Context<'_>) -> Poll<Result<()>> {
Poll::Ready(Err(Error::new(
ErrorKind::Unsupported,
"HdfsNativeWriter doesn't support abort",
)))
}
}