2016-09-20 5 views
1

스칼라의 FileIO.fromPath에서 akka Bytestring을 가져 오는 관용적 인 방법은 무엇입니까? map관용법으로 FileIO.fromPath에서 Bytestring을 얻는 방법

FileIO.fromPath(Paths.get("some file path")).map { byteString => 
    doSomething() 
} 
+0

당신은 사용 사례에 대해 더 이상 추가 할 수 있습니까? '''FileIO.fromPath'''는'''Source''를 생성합니다. 그러면 다음과 같이 많은 것을 할 수 있습니다. – Barry

+0

ByteString으로 메모리에있는 파일을 읽고 싶습니다. – Rabzu

답변

2

같은 Source 사용 기능에서

0

변환 bytestrings 내가 가장 간단한 방법은 runFold을 사용하는 것입니다 믿습니다 :

FileIO.fromPath(Paths.get("some file path")) 
    .runFold(ByteString.empty)(_ ++ _) 

이것은 Future[ByteString] 반환합니다. 말했다

, 그것은 매우 가능성이 그 단지 ByteString에 결과 Array[Byte] 더 효율적입니다 변환 후 Files.readAllBytes에 전체 파일을로드하고 :

ByteString(Files.readAllBytes(Paths.get("some file path"))) 
관련 문제