搜尋
首頁後端開發Golang我想將adb備份的.ab檔解壓縮並寫入tar包

我想將adb備份的.ab檔解壓縮並寫入tar包

php小編子墨可以幫你解答關於adb備份的.ab檔解壓縮並寫入tar包的問題。 adb備份是Android系統中的一種備份方式,產生的備份檔案後綴名為.ab。如果你想解壓縮和寫入tar包,可以透過使用ADB工具和tar指令來完成。首先,使用ADB指令將.ab檔轉換為tar包,然後再使用tar指令解壓縮tar包。這樣就可以將備份檔還原到tar包。希望這個回答對你有幫助!

問題內容

我按照以下方式處理

bf, err := os.Open(backupFilePath)
if err != nil {
    fmt.Println("os.Open: ", err)
    return
}
defer bf.Close()
rd := bufio.NewReader(bf)

tarFile, err := os.Create(tarFilePath)
if err != nil {
    fmt.Println("os.Create: ", err)
    return
}
defer tarFile.Close()

zf, zerr := zlib.NewReader(rd)
if zerr != nil {
    return "", zerr
}
_, err = io.Copy(tarFile, zf)
if err != nil {
    fmt.Println("io.Copy backup.ab -> backup.ab.tar failed:  ", err)
}
zf.Close()

發生錯誤:io.copy backup.ab -> backup.ab.tar 失敗:意外的 eof

出現這種情況是因為 .ab 檔案已損壞還是處理方法錯誤?

解決方法

很可能是 .ab 檔案已損壞。

但是您的程式碼也存在問題。從 .ab 檔案讀取時應跳過前 24 個位元組。否則,您應該會看到此錯誤:zlib:無效的標頭。由於您看到其他內容,我會假設您的 .ab 檔案已損壞。

順便說一句,不需要 rd := bufio.newreader(bf)

這是適合我的示範:

package main

import (
    "compress/zlib"
    "io"
    "os"
)

func main() {
    bf, err := os.open("temp.ab")
    if err != nil {
        panic(err)
    }
    defer bf.close()
    if _, err := bf.seek(24, 0); err != nil {
        panic(err)
    }

    zf, err := zlib.newreader(bf)
    if err != nil {
        panic(err)
    }
    defer zf.close()

    tarfile, err := os.create("temp.tar")
    if err != nil {
        panic(err)
    }
    defer tarfile.close()

    _, err = io.copy(tarfile, zf)
    if err != nil {
        panic(err)
    }
}

更新

使用backup.ab測試了演示,沒有錯誤報導。但生成的tar檔無效:

$ tar tvf backup.tar
<...list of files truncated...>
tar: unexpected eof in archive
tar: error is not recoverable: exiting now

嘗試使用 zlib-flate,得到相同的結果:

$ dd if=backup.ab ibs=24 skip=1 | zlib-flate -uncompress > backup2.tar
$ md5sum backup*.tar
3eff01578dec035367688e03b6ec7a72  backup2.tar
3eff01578dec035367688e03b6ec7a72  backup.tar

嘗試過https://www.php.cn/link/6e67691b60ed3e4a55935261314dd534 a>,也得到了相同的結果。因此 backup.ab 檔案應該已損壞。

$ java -jar ~/Downloads/abe.jar unpack backup.ab backup3.tar
$ md5sum backup*.tar
3eff01578dec035367688e03b6ec7a72  backup2.tar
3eff01578dec035367688e03b6ec7a72  backup3.tar
3eff01578dec035367688e03b6ec7a72  backup.tar

以上是我想將adb備份的.ab檔解壓縮並寫入tar包的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:stackoverflow。如有侵權,請聯絡admin@php.cn刪除
使用GO編程語言構建可擴展系統使用GO編程語言構建可擴展系統Apr 25, 2025 am 12:19 AM

goisidealforbuildingscalablesystemsduetoitssimplicity,效率和建築物內currencysupport.1)go'scleansyntaxandaxandaxandaxandMinimalisticDesignenhanceProductivityAndRedCoductivityAndRedCuceErr.2)ItSgoroutinesAndInesAndInesAndInesAndineSandChannelsEnablenableNablenableNableNablenableFifficConcurrentscorncurrentprogragrammentworking torkermenticmminging

有效地使用Init功能的最佳實踐有效地使用Init功能的最佳實踐Apr 25, 2025 am 12:18 AM

Initfunctionsingorunautomationbeforemain()andareusefulforsettingupenvorments和InitializingVariables.usethemforsimpletasks,避免使用輔助效果,andbecautiouswithTestingTestingTestingAndLoggingTomaintAnainCodeCodeCodeClarityAndTestesto。

INIT函數在GO軟件包中的執行順序INIT函數在GO軟件包中的執行順序Apr 25, 2025 am 12:14 AM

goinitializespackagesintheordertheordertheyimported,thenexecutesInitFunctionswithinApcageIntheirdeFinityOrder,andfilenamesdetermineTheOrderAcractacractacrosmultiplefiles.thisprocessCanbeCanbeinepessCanbeInfleccessByendercrededBydeccredByDependenciesbetenciesbetencemendencenciesbetnependendpackages,whermayleLeadtocomplexinitialitialializizesizization

在GO中定義和使用自定義接口在GO中定義和使用自定義接口Apr 25, 2025 am 12:09 AM

CustomInterfacesingoarecrucialforwritingFlexible,可維護,andTestableCode.TheyEnableDevelostOverostOcusonBehaviorBeiroveration,增強ModularityAndRobustness.byDefiningMethodSigntulSignatulSigntulSignTypaterSignTyperesthattypesmustemmustemmustemmustemplement,InterfaceSallowForCodeRepodEreusaperia

在GO中使用接口進行模擬和測試在GO中使用接口進行模擬和測試Apr 25, 2025 am 12:07 AM

使用接口進行模擬和測試的原因是:接口允許定義合同而不指定實現方式,使得測試更加隔離和易於維護。 1)接口的隱式實現使創建模擬對像變得簡單,這些對像在測試中可以替代真實實現。 2)使用接口可以輕鬆地在單元測試中替換服務的真實實現,降低測試複雜性和時間。 3)接口提供的靈活性使得可以為不同測試用例更改模擬行為。 4)接口有助於從一開始就設計可測試的代碼,提高代碼的模塊化和可維護性。

在GO中使用init進行包裝初始化在GO中使用init進行包裝初始化Apr 24, 2025 pm 06:25 PM

在Go中,init函數用於包初始化。 1)init函數在包初始化時自動調用,適用於初始化全局變量、設置連接和加載配置文件。 2)可以有多個init函數,按文件順序執行。 3)使用時需考慮執行順序、測試難度和性能影響。 4)建議減少副作用、使用依賴注入和延遲初始化以優化init函數的使用。

GO的選擇語句:多路復用並發操作GO的選擇語句:多路復用並發操作Apr 24, 2025 pm 05:21 PM

go'SselectStatementTreamLinesConcurrentProgrambyMultiplexingOperations.1)itallowSwaitingOnMultipleChannEloperations,執行thefirstreadyone.2)theDefirstreadyone.2)thedefefcasepreventlocksbysbysbysbysbysbythoplocktrograpraproxrograpraprocrecrecectefnoopeready.3)

GO中的高級並發技術:上下文和候補組GO中的高級並發技術:上下文和候補組Apr 24, 2025 pm 05:09 PM

contextancandwaitgroupsarecrucialingoformanaginggoroutineseflect.1)context contextsallowsAllowsAllowsAllowsAllowsAllingCancellationAndDeadLinesAcrossapibiboundaries,確保GoroutinesCanbestoppedGrace.2)WaitGroupsSynChronizeGoroutines,確保Allimizegoroutines,確保AllizeNizeGoROutines,確保AllimizeGoroutines

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。