某專案要上傳到 Perforce 做版本控制,不過今天上線人員反映,我提供給他的程式清單、和他從 Perforce 匯出的檔案,有幾個檔案和我的大小不一致,不一致的檔案都足足差了 3 Bytes。

我的檔案列表是,用 C# 的 FileInfo 去取得 Length 後,輸出成上線人員想要的紙本表單:

FileInfo fi = new FileInfo(strFilePath);
string ofileLength = fi.Length.ToString("#,###"); // 檔案大小

這個檔案大小的計算方式用了好久,之前也沒發生問題過。每個有問題的檔案都少 3 Bytes,我原本猜可能是 FileInfo 取到的是什麼特定的屬性,上網查一下,找到 "Why Empty Text File Contains 3 bytes?",裡面有提到 UTF-8 可能會被簽章:

"So, those three bytes you are seeing are the byte order marker for the unicode file I am guessing. For UTF-8, it is three bytes.
You can avoid those by saving the file using UTF-8 without signature."

 

看來是我和上線人員兩造比對的檔案本身就不一樣。

檢查了一下,我原始上傳前的檔案的確是無 BOM 的:

檔案是UTF-8(無BOM)

上線人員從 Perforce 取出的檔案是有 BOM 的:

檔案是UTF-8(有BOM)

 

解決方法是在 Perforce 設定語系,Connection(連線) → Choose Charater Encoding(選擇編碼)。

要在Perforce設定語系

把編碼選定為無 BOM 的 UTF-8,之後就平平安安了。

Perforce要設定成no BOM

 

 

arrow
arrow
    全站熱搜

    小攻城師 發表在 痞客邦 留言(0) 人氣()