Skip to content

Commit

Permalink
Merge branch 'release-v0.3.1' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Nov 6, 2016
2 parents 28d9b9b + 154c580 commit 7ce33e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "postgres-binary-copy"
version = "0.3.0"
version = "0.3.1"
authors = ["Steven Fackler <sfackler@gmail.com>"]
license = "MIT"
description = "Support for binary-format COPY query execution with postgres"
documentation = "https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0/postgres_binary_copy"
documentation = "https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.1/postgres_binary_copy"
repository = "https://github.com/sfackler/rust-postgres-binary-copy"
readme = "README.md"
keywords = ["database", "sql", "postgres", "copy"]

[dependencies]
byteorder = "0.5"
postgres = "0.12"
postgres = ">= 0.12, < 0.14"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Support for binary-format `COPY` query execution with
[rust-postgres](https://github.com/sfackler/rust-postgres).

[Documentation](https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0/postgres_binary_copy)
[Documentation](https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.1/postgres_binary_copy)

## Example

Expand Down
24 changes: 7 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
//! stmt.copy_in(&[], &mut reader).unwrap();
//! }
//! ```
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.0")]
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-binary-copy/doc/v0.3.1")]
#![warn(missing_docs)]
extern crate byteorder;
extern crate postgres;

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use postgres::error::Error;
use postgres::types::{Type, ToSql, IsNull};
use postgres::stmt::{CopyInfo, ReadWithInfo, WriteWithInfo};
use std::cmp;
use std::error;
use std::fmt;
use std::io::prelude::*;
use std::io::{self, Cursor};
Expand Down Expand Up @@ -151,10 +149,8 @@ impl<'a, I> BinaryCopyReader<'a, I>
if idx == 0 {
let len = self.types.len();
let len = if len > i16::max_value() as usize {
let err: Box<error::Error + Sync + Send> = "value too large to transmit"
.into();
return Err(io::Error::new(io::ErrorKind::InvalidInput,
Error::Conversion(err)));
"value too large to transmit"));
} else {
len as i16
};
Expand All @@ -170,11 +166,8 @@ impl<'a, I> BinaryCopyReader<'a, I>
Ok(IsNull::No) => {
let len = self.buf.get_ref().len() as u64 - 4 - len_pos;
if len > i32::max_value() as u64 {
let err: Box<error::Error + Sync + Send> = "value too large to \
transmit"
.into();
return Err(io::Error::new(io::ErrorKind::InvalidInput,
Error::Conversion(err)));
"value too large to transmit"));
} else {
len as i32
}
Expand Down Expand Up @@ -293,17 +286,16 @@ impl<W> BinaryCopyWriter<W>
}

if &self.buf[..HEADER_MAGIC.len()] != HEADER_MAGIC {
let err: Box<error::Error + Sync + Send> = "Did not receive expected header".into();
return Err(io::Error::new(io::ErrorKind::InvalidInput, err));
return Err(io::Error::new(io::ErrorKind::InvalidInput, "invalid header"));
}

let flags = try!((&mut &self.buf[HEADER_MAGIC.len()..]).read_i32::<BigEndian>());

self.has_oids = (flags & 1 << 16) != 0;

if (flags & !0 << 17) != 0 {
let err: Box<error::Error + Sync + Send> = "Critical file format issue".into();
return Err(io::Error::new(io::ErrorKind::InvalidInput, err));
return Err(io::Error::new(io::ErrorKind::InvalidInput,
"critical file format issue"));
}

self.buf.clear();
Expand Down Expand Up @@ -393,9 +385,7 @@ impl<W> WriteWithInfo for BinaryCopyWriter<W>
WriteState::AtFieldSize(remaining) => self.read_field_size(buf, info, remaining),
WriteState::AtField { size, remaining } => self.read_field(buf, info, size, remaining),
WriteState::Done => {
let err: Box<error::Error + Sync + Send> = "Unexpected input after stream end"
.into();
Err(io::Error::new(io::ErrorKind::InvalidInput, err))
Err(io::Error::new(io::ErrorKind::InvalidInput, "unexpected input after EOF"))
}
}
}
Expand Down

0 comments on commit 7ce33e0

Please sign in to comment.