Skip to content

Commit eefea02

Browse files
committed
Add example and README content
1 parent e0f48e8 commit eefea02

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
# rust-postgres-large-object
2+
3+
[![Build Status](https://travis-ci.org/sfackler/rust-postgres-large-object.svg?branch=master)](https://travis-ci.org/sfackler/rust-postgres-large-object)
4+
5+
A crate providing access to the Postgres large object API.
6+
7+
Documentation is available [here](https://sfackler.github.io/rust-postrgres-large-object/doc/postgres_large_object).
8+
9+
# Example
10+
11+
```rust,no_run
12+
extern crate postgres;
13+
extern crate postgres_large_object;
14+
15+
use std::old_path::Path;
16+
use std::old_io::fs::File;
17+
use std::old_io::util;
18+
19+
use postgres::{Connection, SslMode};
20+
use postgres_large_object::{LargeObjectExt, LargeObjectTransactionExt, Mode};
21+
22+
fn main() {
23+
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
24+
25+
let mut file = File::open(&Path::new("vacation_photos.tar.gz")).unwrap();
26+
let trans = conn.transaction().unwrap();
27+
let oid = trans.create_large_object().unwrap();
28+
{
29+
let mut large_object = trans.open_large_object(oid, Mode::Write).unwrap();
30+
util::copy(&mut file, &mut large_object).unwrap();
31+
}
32+
trans.commit().unwrap();
33+
34+
let mut file = File::create(&Path::new("vacation_photos_copy.tar.gz")).unwrap();
35+
let trans = conn.transaction().unwrap();
36+
let mut large_object = trans.open_large_object(oid, Mode::Read).unwrap();
37+
util::copy(&mut large_object, &mut file).unwrap();
38+
}
39+
```

src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
//! A crate providing access to the Postgres large object API.
2+
//!
3+
//! # Example
4+
//!
5+
//! ```rust,no_run
6+
//! extern crate postgres;
7+
//! extern crate postgres_large_object;
8+
//!
9+
//! use std::old_path::Path;
10+
//! use std::old_io::fs::File;
11+
//! use std::old_io::util;
12+
//!
13+
//! use postgres::{Connection, SslMode};
14+
//! use postgres_large_object::{LargeObjectExt, LargeObjectTransactionExt, Mode};
15+
//!
16+
//! fn main() {
17+
//! let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
18+
//!
19+
//! let mut file = File::open(&Path::new("vacation_photos.tar.gz")).unwrap();
20+
//! let trans = conn.transaction().unwrap();
21+
//! let oid = trans.create_large_object().unwrap();
22+
//! {
23+
//! let mut large_object = trans.open_large_object(oid, Mode::Write).unwrap();
24+
//! util::copy(&mut file, &mut large_object).unwrap();
25+
//! }
26+
//! trans.commit().unwrap();
27+
//!
28+
//! let mut file = File::create(&Path::new("vacation_photos_copy.tar.gz")).unwrap();
29+
//! let trans = conn.transaction().unwrap();
30+
//! let mut large_object = trans.open_large_object(oid, Mode::Read).unwrap();
31+
//! util::copy(&mut large_object, &mut file).unwrap();
32+
//! }
33+
//! ```
234
#![feature(unsafe_destructor, io, core)]
335
#![doc(html_root_url="https://sfackler.github.io/rust-postgres-large-object/doc")]
436

0 commit comments

Comments
 (0)