Movatterモバイル変換
[0]ホーム
{-# LANGUAGE Trustworthy #-}{-# LANGUAGE CPP , NoImplicitPrelude , BangPatterns #-}-- -------------------------------------------------------------------------------- (c) The University of Glasgow 2006---- Fingerprints for recompilation checking and ABI versioning, and-- implementing fast comparison of Typeable.---- ----------------------------------------------------------------------------moduleGHC.Fingerprint(Fingerprint(..),fingerprint0,fingerprintData,fingerprintString,fingerprintFingerprints,getFileHash)whereimportGHC.IOimportGHC.BaseimportGHC.NumimportGHC.ListimportGHC.RealimportGHC.ShowimportForeignimportForeign.CimportSystem.IOimportGHC.Fingerprint.Type-- for SIZEOF_STRUCT_MD5CONTEXT:#include "HsBaseConfig.h"-- XXX instance Storable Fingerprint-- defined in Foreign.Storable to avoid orphan instancefingerprint0::Fingerprintfingerprint0=Fingerprint00fingerprintFingerprints::[Fingerprint]->FingerprintfingerprintFingerprintsfs=unsafeDupablePerformIO$withArrayLenfs$\lenp->dofingerprintData(castPtrp)(len*sizeOf(headfs))fingerprintData::PtrWord8->Int->IOFingerprintfingerprintDatabuflen=doallocaBytesSIZEOF_STRUCT_MD5CONTEXT$\pctxt->doc_MD5Initpctxtc_MD5Updatepctxtbuf(fromIntegrallen)allocaBytes16$\pdigest->doc_MD5Finalpdigestpctxtpeek(castPtrpdigest::PtrFingerprint)fingerprintString::String->FingerprintfingerprintStringstr=unsafeDupablePerformIO$withArrayLenword8s$\lenp->fingerprintDataplenwhereword8s=concatMapfstrfc=letw32::Word32w32=fromIntegral(ordc)in[fromIntegral(w32`shiftR`24),fromIntegral(w32`shiftR`16),fromIntegral(w32`shiftR`8),fromIntegralw32]-- | Computes the hash of a given file.-- This function loops over the handle, running in constant memory.---- @since 4.7.0.0getFileHash::FilePath->IOFingerprintgetFileHashpath=withBinaryFilepathReadMode$\h->doallocaBytesSIZEOF_STRUCT_MD5CONTEXT$\pctxt->doc_MD5InitpctxtprocessChunksh(\bufsize->c_MD5Updatepctxtbuf(fromIntegralsize))allocaBytes16$\pdigest->doc_MD5Finalpdigestpctxtpeek(castPtrpdigest::PtrFingerprint)where_BUFSIZE=4096-- | Loop over _BUFSIZE sized chunks read from the handle,-- passing the callback a block of bytes and its size.processChunks::Handle->(PtrWord8->Int->IO())->IO()processChunkshf=allocaBytes_BUFSIZE$\arrPtr->letloop=docount<-hGetBufharrPtr_BUFSIZEeof<-hIsEOFhwhen(count/=_BUFSIZE&¬eof)$errorWithoutStackTrace$"GHC.Fingerprint.getFileHash: only read "++showcount++" bytes"farrPtrcountwhen(noteof)loopinloopdataMD5Contextforeignimportccallunsafe"__hsbase_MD5Init"c_MD5Init::PtrMD5Context->IO()foreignimportccallunsafe"__hsbase_MD5Update"c_MD5Update::PtrMD5Context->PtrWord8->CInt->IO()foreignimportccallunsafe"__hsbase_MD5Final"c_MD5Final::PtrWord8->PtrMD5Context->IO()
[8]ページ先頭