# Pastebin lbu13Vm0 import Data.ByteString (ByteString) import Data.ByteString.Unsafe (unsafeUseAsCStringLen) import Data.Vector.Storable (Vector, unsafeFreeze) import Data.Vector.Storable.Mutable (MVector(MVector), unsafeNew) import Foreign (copyArray, withForeignPtr) import Foreign.C (CChar) bsToVec :: ByteString -> IO (Vector CChar) bsToVec bs = unsafeUseAsCStringLen bs $ \(ptr, n) -> do v@(MVector _ foreignPtr) <- unsafeNew n withForeignPtr foreignPtr $ \ptr' -> copyArray ptr' ptr n unsafeFreeze v