-
Notifications
You must be signed in to change notification settings - Fork 348
/
largeobject.scala
32 lines (23 loc) · 1.05 KB
/
largeobject.scala
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
// Copyright (c) 2013-2017 Rob Norris
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT
package doobie.postgres.hi
import cats.implicits._
import doobie.util.io.IOActions
import java.io.{File, InputStream, OutputStream}
object largeobject {
import implicits._
lazy val io = new IOActions[LargeObjectIO]
def copyFromFile(blockSize: Int, file: File): LargeObjectIO[Unit] =
PFLO.getOutputStream.flatMap { os => io.copyFileToStream(blockSize, file, os) *> io.flush(os) }
def copyToFile(blockSize: Int, file: File): LargeObjectIO[Unit] =
PFLO.getInputStream.flatMap { is => io.copyStreamToFile(blockSize, file, is) }
def copyFromStream(blockSize: Int, is: InputStream): LargeObjectIO[Unit] =
PFLO.getOutputStream.flatMap { os =>
io.copyStream(new Array[Byte](blockSize))(is, os)
}
def copyToStream(blockSize: Int, os: OutputStream): LargeObjectIO[Unit] =
PFLO.getInputStream.flatMap { is =>
io.copyStream(new Array[Byte](blockSize))(is, os)
}
}