This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Ammonite REPL to run this example: https://ammonite.io/ | |
import $ivy.`org.typelevel::cats-core:2.0.0`, cats.syntax.either._, $ivy.`com.chuusai::shapeless:2.3.3`, shapeless._ | |
trait CsvValueDecoder[A] { | |
def decode(value: String): Either[String, A] | |
} | |
object CsvValueDecoder { | |
def create[A](f: String => Either[String, A]): CsvValueDecoder[A] = (value: String) => f(value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.stream.scaladsl.{Compression, JsonFraming} | |
import akka.util.ByteString | |
import org.bson.Document | |
import akka.stream.scaladsl.{Sink, Source} | |
val maximumObjectLength = 16000000 | |
s3Client | |
.download(bucket, fileName) | |
.via(Compression.gunzip()) | |
.via(JsonFraming.objectScanner(maximumObjectLength)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.stream.scaladsl.{Compression, JsonFraming} | |
val maximumObjectLength = 16000000 | |
s3Client | |
.download("backup.bucket", "CookieCollectionBackup") | |
.via(Compression.gunzip()) | |
.via(JsonFraming.objectScanner(maximumObjectLength)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.stream.scaladsl.Compression | |
s3Client | |
.download("backup.bucket", "CookieCollectionBackup") | |
.via(Compression.gunzip()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s3Client | |
.download(bucket = "backup.bucket", key = "CookieCollectionBackup") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source.fromPublisher(collection.find(): Publisher[org.bson.Document]) | |
.map((doc: org.bson.Document) ⇒ doc.toJson()) | |
.map((json: String) ⇒ ByteString(json)) | |
.via(Compression.gzip: Flow[ByteString, ByteString, NotUsed]) | |
.runWith(s3Sink) | |
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] = | |
s3Client.multipartUploadWithHeaders( | |
bucket = "mycookiesbucket12345", | |
key = "CookieCollectionBackup.json", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source.fromPublisher(collection.find(): Publisher[org.bson.Document]) | |
.map((doc: org.bson.Document) ⇒ doc.toJson()) | |
.map((json: String) ⇒ ByteString(json)) | |
.via(Compression.gzip: Flow[ByteString, ByteString, NotUsed]) | |
.runWith(s3Sink) | |
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] = | |
s3Client.multipartUpload( | |
bucket = "bucketWithCookies", | |
key = "CookieCollectionBackup.json" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Source.fromPublisher(collection.find(): Publisher[org.bson.Document]) | |
.map((doc: org.bson.Document) ⇒ doc.toJson()) | |
.map((json: String) ⇒ ByteString(json)) | |
.runWith(s3Sink) | |
val s3Sink: Sink[ByteString, Future[MultipartUploadResult]] = | |
s3Client.multipartUpload( | |
bucket = "bucketWithCookies", | |
key = "CookieCollectionBackup.json" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const server = http.createServer(); | |
server.on('request', (request, response) => { | |
let body = []; | |
request.on('data', (chunk) => { | |
body.push(chunk); | |
}).on('end', () => { | |
body = Buffer.concat(body).toString(); |