Skip to content

Commit

Permalink
Merge pull request readium#195 from readium/test/keepclear
Browse files Browse the repository at this point in the history
Test/keepclear
  • Loading branch information
llemeurfr authored May 2, 2019
2 parents 7bfabe8 + 2b6e0ec commit 66d2a9a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 63 deletions.
32 changes: 6 additions & 26 deletions epub/epub.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
// Copyright (c) 2016 Readium Foundation
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
// 3. Neither the name of the organization nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright 2019 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.

package epub

import (
"archive/zip"
"io"
"path/filepath"
"sort"
"strings"

Expand Down Expand Up @@ -73,7 +52,7 @@ func (ep Epub) Cover() (bool, *Resource) {
if strings.Contains(it.Properties, "cover-image") ||
it.Id == coverImageID {

path := filepath.Join(p.BasePath, it.Href)
path := p.BasePath + "/" + it.Href
for _, r := range ep.Resource {
if r.Path == path {
return true, r
Expand Down Expand Up @@ -104,5 +83,6 @@ type Resource struct {

func (ep Epub) CanEncrypt(file string) bool {
i := sort.SearchStrings(ep.cleartextResources, file)

return i >= len(ep.cleartextResources) || ep.cleartextResources[i] != file
}
43 changes: 6 additions & 37 deletions epub/reader.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
// Copyright (c) 2016 Readium Foundation
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
// 3. Neither the name of the organization nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Copyright 2019 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.

package epub

Expand Down Expand Up @@ -70,16 +50,6 @@ func findRootFiles(r io.Reader) ([]rootFile, error) {
return roots, nil
}

func (ep *Epub) addCleartextResources(names []string) {
if ep.cleartextResources == nil {
ep.cleartextResources = []string{}
}

for _, name := range names {
ep.cleartextResources = append(ep.cleartextResources, name)
}
}

func (ep *Epub) addCleartextResource(name string) {
if ep.cleartextResources == nil {
ep.cleartextResources = []string{}
Expand Down Expand Up @@ -184,8 +154,6 @@ func Read(r *zip.Reader) (Epub, error) {
ep.Encryption = encryption
sort.Strings(ep.cleartextResources)

//log.Print(fmt.Sprintf("%v", ep.cleartextResources))

return ep, nil
}

Expand All @@ -205,8 +173,9 @@ func addCleartextResources(ep *Epub, p opf.Package) {
item.Id == coverImageID ||
strings.Contains(item.Properties, "nav") ||
item.MediaType == ContentType_NCX {
// re-construct a path, avoids insertion of backslash as separator on Windows.
ep.addCleartextResource(p.BasePath + "/" + item.Href)

ep.addCleartextResource(filepath.Join(p.BasePath, item.Href))
}
}
}
Expand Down

0 comments on commit 66d2a9a

Please sign in to comment.