Created
October 22, 2012 21:08
-
-
Save pke/3934325 to your computer and use it in GitHub Desktop.
unzip component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CreationCollisionOption = Windows.Storage.CreationCollisionOption | |
describe 'Zip component', -> | |
it 'should handle OpenDocument containers', -> | |
spec.async -> | |
uri = "resource/test1.odt".toAppPackageUri() | |
stream = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri) | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
expect(archive.files.length).toEqual 17 | |
archive.getFileContentsAsync('meta.xml') | |
.then (buffer) -> | |
expect(buffer).toBeTruthy() | |
.then -> | |
archive.getFileContentsAsync('settings.xml') | |
.then (buffer) -> | |
expect(buffer).toBeTruthy() | |
it 'should handle Office Open XML containers', -> | |
spec.async -> | |
uri = "resource/test1.docx".toAppPackageUri() | |
stream = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri) | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
expect(archive.files.length).toEqual 9 | |
archive.getFileContentsAsync('docProps/core.xml') | |
.then (buffer) -> | |
expect(buffer).toBeTruthy() | |
it 'should extract single files to disk', -> | |
tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder | |
spec.async -> | |
uri = "resource/test1.odt".toAppPackageUri() | |
stream = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri) | |
tempFolder.createFileAsync('temp_meta.xml', CreationCollisionOption.replaceExisting) | |
.then (destinationFile) -> | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
# meta.xml is stored uncompressed | |
archive.extractFileAsync('meta.xml', destinationFile) | |
.then -> | |
destinationFile.getBasicPropertiesAsync() | |
.then (fileProperties) -> | |
expect(fileProperties.size).toBeGreaterThan 0 | |
tempFolder.createFileAsync('temp_content.xml', CreationCollisionOption.replaceExisting) | |
.then (destinationFile) -> | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
# content.xml is stored deflated | |
archive.extractFileAsync('content.xml', destinationFile) | |
.then -> | |
destinationFile.getBasicPropertiesAsync() | |
.then (fileProperties) -> | |
expect(fileProperties.size).toBeGreaterThan 0 | |
it 'should extract whole archives to disk', -> | |
tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder | |
spec.async -> | |
tempFolder.createFolderAsync('unzipped', CreationCollisionOption.replaceExisting) | |
.then (folder) -> | |
uri = "resource/test1.odt".toAppPackageUri() | |
stream = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri) | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
archive.extractAllAsync(folder) | |
.then -> | |
queryOptions = new Windows.Storage.Search.QueryOptions() | |
queryOptions.folderDepth = Windows.Storage.Search.FolderDepth.deep | |
fileQueryResults = folder.createFileQueryWithOptions(queryOptions) | |
fileQueryResults.getFilesAsync() | |
.then (extractedFiles) -> | |
expect(extractedFiles.length).toBeGreaterThan 0 | |
it 'should throw invalid argument exception for non-existing files', -> | |
tempFolder = Windows.Storage.ApplicationData.current.temporaryFolder | |
spec.async -> | |
uri = "resource/test1.odt".toAppPackageUri() | |
stream = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri) | |
tempFolder.createFileAsync('temp.xml', CreationCollisionOption.replaceExisting) | |
.then (destinationFile) -> | |
runtime.zip.ZipArchive.createFromStreamReferenceAsync(stream) | |
.then (archive) -> | |
archive.extractFileAsync('foobar.dat', destinationFile) | |
.then -> | |
jasmine.getEnv().currentSpec.fail("This should have failed") | |
, (error) -> | |
expect(error.number).toEqual -2147024809 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment